diff --git a/src/Skybrud.Essentials/Time/EssentialsDate.cs b/src/Skybrud.Essentials/Time/EssentialsDate.cs
index d227163..222ed4f 100644
--- a/src/Skybrud.Essentials/Time/EssentialsDate.cs
+++ b/src/Skybrud.Essentials/Time/EssentialsDate.cs
@@ -439,7 +439,7 @@ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] stri
/// An object that supplies culture-specific formatting information.
/// A string representation of value of the current object as specified by and .
public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? provider) {
- return _dateTime.ToString(format, provider);
+ return _dateTime.ToString(string.IsNullOrWhiteSpace(format) ? "yyyy-MM-dd" : format, provider);
}
#endregion
diff --git a/src/Skybrud.Essentials/Time/EssentialsTime.cs b/src/Skybrud.Essentials/Time/EssentialsTime.cs
index 802d144..ff0a18c 100644
--- a/src/Skybrud.Essentials/Time/EssentialsTime.cs
+++ b/src/Skybrud.Essentials/Time/EssentialsTime.cs
@@ -791,7 +791,7 @@ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] stri
/// An object that supplies culture-specific formatting information.
/// A string representation of value of the current object as specified by and .
public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? provider) {
- return DateTimeOffset.ToString(format, provider);
+ return string.IsNullOrWhiteSpace(format) ? Iso8601 : DateTimeOffset.ToString(format, provider);
}
///
diff --git a/src/TestProject1/Time/EssentialsDateTests.cs b/src/TestProject1/Time/EssentialsDateTests.cs
index 532066d..18e6ac8 100644
--- a/src/TestProject1/Time/EssentialsDateTests.cs
+++ b/src/TestProject1/Time/EssentialsDateTests.cs
@@ -13,8 +13,9 @@ public void ToStringDefault() {
EssentialsDate date = new(2024, 3, 27);
- Assert.AreEqual("2024-03-27", date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
- Assert.AreEqual("2024-03-27", date.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("da-DK")));
+ Assert.AreEqual("2024-03-27", date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), "#1");
+ Assert.AreEqual("2024-03-27", date.ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("da-DK")), "#2");
+ Assert.AreEqual("2024-03-27", $"{date}", "#3");
}
diff --git a/src/TestProject1/Time/EssentialsTimeTests.cs b/src/TestProject1/Time/EssentialsTimeTests.cs
index 9a54ec2..1053887 100644
--- a/src/TestProject1/Time/EssentialsTimeTests.cs
+++ b/src/TestProject1/Time/EssentialsTimeTests.cs
@@ -13,7 +13,8 @@ public void ToStringDefault() {
EssentialsTime time = new(2024, 3, 27, 12, 0, 0, TimeZoneInfo.Utc);
- Assert.AreEqual("2024-03-27T12:00:00.000Z", time.ToString());
+ Assert.AreEqual("2024-03-27T12:00:00.000Z", time.ToString(), "#1");
+ Assert.AreEqual("2024-03-27T12:00:00.000Z", $"{time}", "#2");
}
diff --git a/src/UnitTestProject1/Time/Time/EssentialsDateTests.cs b/src/UnitTestProject1/Time/Time/EssentialsDateTests.cs
index 23db8f2..55543de 100644
--- a/src/UnitTestProject1/Time/Time/EssentialsDateTests.cs
+++ b/src/UnitTestProject1/Time/Time/EssentialsDateTests.cs
@@ -235,6 +235,17 @@ public void Max() {
}
+ [TestMethod]
+ public void ToStringDefault() {
+
+ EssentialsDate date = new EssentialsDate(2024, 4, 7);
+
+ Assert.AreEqual("2024-04-07", date.ToString());
+ Assert.AreEqual("2024-04-07", $"{date}");
+ Assert.AreEqual("2024-04-07", $"{date:yyyy-MM-dd}");
+
+ }
+
}
}
\ No newline at end of file