diff --git a/src/Skybrud.Essentials/Time/Extensions/DateTimeExtensions.cs b/src/Skybrud.Essentials/Time/Extensions/DateTimeExtensions.cs
index bd6892c..08dece2 100644
--- a/src/Skybrud.Essentials/Time/Extensions/DateTimeExtensions.cs
+++ b/src/Skybrud.Essentials/Time/Extensions/DateTimeExtensions.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
+using Newtonsoft.Json;
using Skybrud.Essentials.Time.Iso8601;
namespace Skybrud.Essentials.Time.Extensions {
@@ -344,6 +345,40 @@ public static string ToIso8601(this DateTime value) {
return value is null ? null : Iso8601Utils.ToString(value.Value);
}
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsDate? ToEssentialsDate(this DateTime? time) {
+ return time is null ? null : new EssentialsDate(time.Value);
+ }
+
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsTime? ToEssentialsTime(this DateTime? time) {
+ return time is null ? null : new EssentialsTime(time.Value);
+ }
+
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// The time zone the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsTime? ToEssentialsTime(this DateTime? time, TimeZoneInfo timeZone) {
+ return time is null ? null : new EssentialsTime(time.Value, timeZone);
+ }
+
}
}
\ No newline at end of file
diff --git a/src/Skybrud.Essentials/Time/Extensions/DateTimeOffsetExtensions.cs b/src/Skybrud.Essentials/Time/Extensions/DateTimeOffsetExtensions.cs
index bad95e7..52e2d4e 100644
--- a/src/Skybrud.Essentials/Time/Extensions/DateTimeOffsetExtensions.cs
+++ b/src/Skybrud.Essentials/Time/Extensions/DateTimeOffsetExtensions.cs
@@ -344,6 +344,40 @@ public static string ToIso8601(this DateTimeOffset value) {
return value is null ? null : Iso8601Utils.ToString(value.Value);
}
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsDate? ToEssentialsDate(this DateTimeOffset? time) {
+ return time is null ? null : new EssentialsDate(time.Value);
+ }
+
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsTime? ToEssentialsTime(this DateTimeOffset? time) {
+ return time is null ? null : new EssentialsTime(time.Value);
+ }
+
+ ///
+ /// Returns a new instance based on the specified , or
+ /// if is .
+ ///
+ /// The date and time the new instance should be based on.
+ /// The time zone the new instance should be based on.
+ /// An instance of , or if is .
+ [return: NotNullIfNotNull(nameof(time))]
+ public static EssentialsTime? ToEssentialsTime(this DateTimeOffset? time, TimeZoneInfo timeZone) {
+ return time is null ? null : new EssentialsTime(time.Value, timeZone);
+ }
+
}
}
\ No newline at end of file