diff --git a/lib/YANLib/Nullable/YANDateTime.Nullable.cs b/lib/YANLib/Nullable/YANDateTime.Nullable.cs
index ad309cb..21fb36d 100644
--- a/lib/YANLib/Nullable/YANDateTime.Nullable.cs
+++ b/lib/YANLib/Nullable/YANDateTime.Nullable.cs
@@ -24,7 +24,7 @@ public static partial class YANDateTime
/// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal)
{
- if (strs.AllNullOrWhiteSpace())
+ if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
diff --git a/lib/YANLib/Nullable/YANDateTime.cs b/lib/YANLib/Nullable/YANDateTime.cs
index 6b78c6e..e1f49ca 100644
--- a/lib/YANLib/Nullable/YANDateTime.cs
+++ b/lib/YANLib/Nullable/YANDateTime.cs
@@ -25,7 +25,7 @@ public static partial class YANDateTime
/// An enumerable collection of objects for each successfully converted input string.
public static IEnumerable ToDateTime(this IEnumerable strs)
{
- if (strs.AllNullOrWhiteSpace())
+ if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
@@ -53,7 +53,7 @@ public static partial class YANDateTime
/// An enumerable collection of objects for each successfully converted input string in the specified format.
public static IEnumerable ToDateTime(this IEnumerable strs, string fmt)
{
- if (strs.AllNullOrWhiteSpace())
+ if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
@@ -83,7 +83,7 @@ public static partial class YANDateTime
/// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal)
{
- if (strs.AllNullOrWhiteSpace())
+ if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
diff --git a/lib/YANLib/Ultimate/YANDateTime.Nullable.cs b/lib/YANLib/Ultimate/YANDateTime.Nullable.cs
new file mode 100644
index 0000000..cd802d4
--- /dev/null
+++ b/lib/YANLib/Ultimate/YANDateTime.Nullable.cs
@@ -0,0 +1,210 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace YANLib.Ultimate;
+
+public static partial class YANDateTime
+{
+ ///
+ /// Converts a collection of string representations of dates and times to their equivalents using the specified format.
+ /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert.
+ ///
+ /// The collection of strings to be converted to .
+ /// The format of the input strings.
+ /// The default value to return for any strings that fail to convert.
+ /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
+ public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal)
+ {
+ if (strs.AllWhiteSpaceOrNull())
+ {
+ yield break;
+ }
+ foreach (var str in strs)
+ {
+ yield return str.ToDateTime(fmt, dfltVal);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GetWeekOfYear(this IEnumerable dts)
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.GetWeekOfYear();
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzDst);
+ }
+ }
+}
diff --git a/lib/YANLib/Ultimate/YANDateTime.cs b/lib/YANLib/Ultimate/YANDateTime.cs
new file mode 100644
index 0000000..e215dd0
--- /dev/null
+++ b/lib/YANLib/Ultimate/YANDateTime.cs
@@ -0,0 +1,105 @@
+namespace YANLib.Ultimate;
+
+public static partial class YANDateTime
+{
+ ///
+ /// Converts a collection of string representations of dates and times to their equivalents.
+ /// Returns an enumerable collection of objects for each successfully converted input string, and skips any strings that fail to convert.
+ ///
+ /// The collection of strings to be converted to .
+ /// An enumerable collection of objects for each successfully converted input string.
+ public static IEnumerable ToDateTime(this IEnumerable strs)
+ {
+ if (strs.AllWhiteSpaceOrNull())
+ {
+ yield break;
+ }
+ foreach (var str in strs)
+ {
+ yield return str.ToDateTime();
+ }
+ }
+
+ ///
+ /// Converts a collection of string representations of dates and times to their equivalents using the specified format.
+ /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and skips any strings that fail to convert.
+ ///
+ /// The collection of strings to be converted to .
+ /// The format of the input strings.
+ /// An enumerable collection of objects for each successfully converted input string in the specified format.
+ public static IEnumerable ToDateTime(this IEnumerable strs, string fmt)
+ {
+ if (strs.AllWhiteSpaceOrNull())
+ {
+ yield break;
+ }
+ foreach (var str in strs)
+ {
+ yield return str.ToDateTime(fmt);
+ }
+ }
+
+ ///
+ /// Converts a collection of string representations of dates and times to their equivalents using the specified format.
+ /// Returns an enumerable collection of objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert.
+ ///
+ /// The collection of strings to be converted to .
+ /// The format of the input strings.
+ /// The default value to return for any strings that fail to convert.
+ /// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
+ public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal)
+ {
+ if (strs.AllWhiteSpaceOrNull())
+ {
+ yield break;
+ }
+ foreach (var str in strs)
+ {
+ yield return str.ToDateTime(fmt, dfltVal);
+ }
+ }
+
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct
+ {
+ for (var i = 0ul; i < size.ToUlong(); i++)
+ {
+ yield return YANLib.YANDateTime.GenerateRandomDateTime(min, max);
+ }
+ }
+
+ public static IEnumerable GetWeekOfYear(this IEnumerable dts)
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.GetWeekOfYear();
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzSrc, tzDst);
+ }
+ }
+
+ public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct
+ {
+ if (dts is null || !dts.Any())
+ {
+ yield break;
+ }
+ foreach (var dt in dts)
+ {
+ yield return dt.ChangeTimeZone(tzDst);
+ }
+ }
+}
diff --git a/lib/YANLib/YANDateTime.Nullable.cs b/lib/YANLib/YANDateTime.Nullable.cs
index ee22aca..6869ab9 100644
--- a/lib/YANLib/YANDateTime.Nullable.cs
+++ b/lib/YANLib/YANDateTime.Nullable.cs
@@ -1,4 +1,6 @@
-using static System.DateTime;
+using System.Linq;
+using static System.DateTime;
+using static System.Linq.Enumerable;
namespace YANLib;
@@ -22,17 +24,7 @@ public static partial class YANDateTime
/// The format of the input strings.
/// The default value to return for any strings that fail to convert.
/// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
- public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal)
- {
- if (strs.AllNullOrWhiteSpace())
- {
- yield break;
- }
- foreach (var str in strs)
- {
- yield return str.ToDateTime(fmt, dfltVal);
- }
- }
+ public static IEnumerable? ToDateTime(this IEnumerable strs, string fmt, DateTime? dfltVal) => strs.AllWhiteSpaceOrNull() ? default : strs.Select(s => s.ToDateTime(fmt, dfltVal));
///
/// Generates a random object between the specified minimum and maximum values.
@@ -65,67 +57,21 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st
/// A randomly generated object between the minimum value and the specified maximum value.
public static DateTime GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default;
- public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
- public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime? max, T? size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
- public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
- public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime? max, T? size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
- public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
- public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime? min, DateTime max, T? size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
public static int GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default;
- public static IEnumerable GetWeekOfYear(this IEnumerable dts)
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.GetWeekOfYear();
- }
- }
+ public static IEnumerable? GetWeekOfYear(this IEnumerable dts) => dts is null || !dts.Any() ? default : dts.Select(d => d.GetWeekOfYear());
public static int TotalMonths(DateTime? dt1, DateTime dt2) => dt1.HasValue ? TotalMonths(dt1.Value, dt2) : default;
@@ -135,17 +81,7 @@ public static IEnumerable GetWeekOfYear(this IEnumerable dts)
public static DateTime ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default;
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
{
@@ -160,17 +96,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T
public static DateTime ChangeTimeZone(this DateTime dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
{
@@ -185,17 +111,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, T
public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzDst.HasValue ? dt.ChangeTimeZone(tzSrc, tzDst.Value) : dt;
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
{
@@ -210,17 +126,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2
public static DateTime ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default;
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2 tzDst) where T1 : struct where T2 : struct
{
@@ -235,17 +141,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc,
public static DateTime ChangeTimeZone(this DateTime? dt, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default;
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2? tzDst) where T1 : struct where T2 : struct
{
@@ -260,17 +156,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T
public static DateTime ChangeTimeZone(this DateTime dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => tzSrc.HasValue ? dt.ChangeTimeZone(tzSrc.Value, tzDst) : dt.ChangeTimeZone(tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
{
@@ -285,17 +171,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc, T
public static DateTime ChangeTimeZone(this DateTime? dt, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dt.HasValue ? dt.Value.ChangeTimeZone(tzSrc, tzDst) : default;
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1? tzSrc, T2? tzDst) where T1 : struct where T2 : struct
{
@@ -310,17 +186,7 @@ public static void ChangeTimeZone(this IList dts, T1? tzSrc,
public static DateTime ChangeTimeZone(this DateTime? dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzDst));
public static void ChangeTimeZone(this IList dts, T tzDst) where T : struct
{
@@ -335,17 +201,7 @@ public static void ChangeTimeZone(this IList dts, T tzDst) where T
public static DateTime ChangeTimeZone(this DateTime dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzDst));
public static void ChangeTimeZone(this IList dts, T? tzDst) where T : struct
{
@@ -360,17 +216,7 @@ public static void ChangeTimeZone(this IList dts, T? tzDst) where T
public static DateTime ChangeTimeZone(this DateTime? dt, T? tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T? tzDst) where T : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzDst));
public static void ChangeTimeZone(this IList dts, T? tzDst) where T : struct
{
diff --git a/lib/YANLib/YANDateTime.cs b/lib/YANLib/YANDateTime.cs
index 9c17504..f8bb3eb 100644
--- a/lib/YANLib/YANDateTime.cs
+++ b/lib/YANLib/YANDateTime.cs
@@ -2,6 +2,7 @@
using static System.Globalization.CultureInfo;
using static System.Globalization.DateTimeFormatInfo;
using static System.Globalization.DateTimeStyles;
+using static System.Linq.Enumerable;
using static System.Math;
using static YANLib.YANNum;
@@ -23,17 +24,7 @@ public static partial class YANDateTime
///
/// The collection of strings to be converted to .
/// An enumerable collection of objects for each successfully converted input string.
- public static IEnumerable ToDateTime(this IEnumerable strs)
- {
- if (strs.AllNullOrWhiteSpace())
- {
- yield break;
- }
- foreach (var str in strs)
- {
- yield return str.ToDateTime();
- }
- }
+ public static IEnumerable? ToDateTime(this IEnumerable strs) => strs.AllWhiteSpaceOrNull() ? default : strs.Select(s => s.ToDateTime());
///
/// Converts the specified string representation of a date and time to its equivalent using the specified format.
@@ -51,17 +42,7 @@ public static IEnumerable ToDateTime(this IEnumerable strs)
/// The collection of strings to be converted to .
/// The format of the input strings.
/// An enumerable collection of objects for each successfully converted input string in the specified format.
- public static IEnumerable ToDateTime(this IEnumerable strs, string fmt)
- {
- if (strs.AllNullOrWhiteSpace())
- {
- yield break;
- }
- foreach (var str in strs)
- {
- yield return str.ToDateTime(fmt);
- }
- }
+ public static IEnumerable? ToDateTime(this IEnumerable strs, string fmt) => strs.AllWhiteSpaceOrNull() ? default : strs.Select(s => s.ToDateTime(fmt));
///
/// Converts the specified string representation of a date and time to its equivalent using the specified format.
@@ -81,17 +62,7 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st
/// The format of the input strings.
/// The default value to return for any strings that fail to convert.
/// An enumerable collection of objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.
- public static IEnumerable ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal)
- {
- if (strs.AllNullOrWhiteSpace())
- {
- yield break;
- }
- foreach (var str in strs)
- {
- yield return str.ToDateTime(fmt, dfltVal);
- }
- }
+ public static IEnumerable? ToDateTime(this IEnumerable strs, string fmt, DateTime dfltVal) => strs.AllWhiteSpaceOrNull() ? default : strs.Select(s => s.ToDateTime(fmt, dfltVal));
///
/// Generates a random object between the specified minimum and maximum values.
@@ -114,27 +85,11 @@ public static IEnumerable ToDateTime(this IEnumerable strs, st
/// A randomly generated object between the minimum value and the specified maximum value.
public static DateTime GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max);
- public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct
- {
- for (var i = 0ul; i < size.ToUlong(); i++)
- {
- yield return GenerateRandomDateTime(min, max);
- }
- }
+ public static IEnumerable GenerateRandomDateTimes(DateTime min, DateTime max, T size) where T : struct => Range(0, size.ToUint().ToInt()).Select(i => GenerateRandomDateTime(min, max));
public static int GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek);
- public static IEnumerable GetWeekOfYear(this IEnumerable dts)
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.GetWeekOfYear();
- }
- }
+ public static IEnumerable? GetWeekOfYear(this IEnumerable dts) => dts is null || !dts.Any() ? default : dts.Select(d => d.GetWeekOfYear());
public static int TotalMonths(DateTime dt1, DateTime dt2) => Abs((dt1.Year - dt2.Year) * 12 + dt1.Month - dt2.Month);
@@ -149,17 +104,7 @@ public static DateTime ChangeTimeZone(this DateTime dt, T1 tzSrc, T2 tzD
};
}
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzSrc, tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzSrc, tzDst));
public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2 tzDst) where T1 : struct where T2 : struct
{
@@ -174,17 +119,7 @@ public static void ChangeTimeZone(this IList dts, T1 tzSrc, T2
public static DateTime ChangeTimeZone(this DateTime dt, T tzDst) where T : struct => dt.ChangeTimeZone(0, tzDst);
- public static IEnumerable ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct
- {
- if (dts is null || !dts.Any())
- {
- yield break;
- }
- foreach (var dt in dts)
- {
- yield return dt.ChangeTimeZone(tzDst);
- }
- }
+ public static IEnumerable? ChangeTimeZone(this IEnumerable dts, T tzDst) where T : struct => dts is null || !dts.Any() ? default : dts.Select(d => d.ChangeTimeZone(tzDst));
public static void ChangeTimeZone(this IList dts, T tzDst) where T : struct
{
diff --git a/lib/YANLib/YANEnumerable.cs b/lib/YANLib/YANEnumerable.cs
index e5a0650..6448549 100644
--- a/lib/YANLib/YANEnumerable.cs
+++ b/lib/YANLib/YANEnumerable.cs
@@ -10,7 +10,7 @@ public static partial class YANEnumerable
public static IEnumerable> ChunkBySize(this List srcs, T1 chunkSize) where T1 : struct
{
var size = chunkSize.ToInt();
- if (srcs.IsNullOrEmpty() && size < 1)
+ if (srcs.IsEmptyOrNull() && size < 1)
{
yield break;
}
@@ -23,7 +23,7 @@ public static IEnumerable> ChunkBySize(this List srcs, T1 chun
public static IEnumerable Clean(this IEnumerable srcs)
{
- if (srcs.IsNullOrEmpty())
+ if (srcs.IsEmptyOrNull())
{
yield break;
}
@@ -49,7 +49,7 @@ public static IEnumerable Clean(this IEnumerable srcs)
public static void Clean(this ICollection srcs)
{
- if (srcs.IsNotNullAndEmpty())
+ if (srcs.IsNotEmptyAndNull())
{
var t = typeof(T);
if (t.IsClass || GetUnderlyingType(t) is not null)
@@ -73,7 +73,7 @@ public static IEnumerable Clean(this IEnumerable srcs)
}
foreach (var src in srcs)
{
- if (src.IsNotNullAndWhiteSpace())
+ if (src.IsNotWhiteSpaceAndNull())
{
yield return src;
}
@@ -86,7 +86,7 @@ public static void Clean(this ICollection srcs)
{
foreach (var src in srcs)
{
- if (src.IsNullOrWhiteSpace())
+ if (src.IsWhiteSpaceOrNull())
{
_ = srcs.Remove(src);
}
@@ -94,19 +94,19 @@ public static void Clean(this ICollection srcs)
}
}
- public static bool IsNullOrEmpty(this IEnumerable srcs) => srcs is null || !srcs.Any();
+ public static bool IsEmptyOrNull(this IEnumerable srcs) => srcs is null || !srcs.Any();
- public static bool IsNullOrEmpty(this IReadOnlyCollection srcs) => srcs is null || srcs.Count < 1;
+ public static bool IsEmptyOrNull(this ICollection srcs) => srcs is null || srcs.Count < 1;
- public static bool IsNotNullAndEmpty(this IEnumerable srcs) => srcs is not null && srcs.Any();
+ public static bool IsNotEmptyAndNull(this IEnumerable srcs) => srcs is not null && srcs.Any();
- public static bool IsNotNullAndEmpty(this IReadOnlyCollection srcs) => srcs is not null && srcs.Count > 0;
+ public static bool IsNotEmptyAndNull(this ICollection srcs) => srcs is not null && srcs.Count > 0;
- public static bool AllNullOrEmpty(IEnumerable srcs) where T : class => !srcs.Any(x => x is not null || x.AnyPropertiesNotDefault());
+ public static bool AllEmptyOrNull(this IEnumerable srcs) where T : class => !srcs.Any(x => x is not null || x.AnyPropertiesNotDefault());
- public static bool AnyNullOrEmpty(IEnumerable srcs) where T : class => srcs.Any(x => x is null || x.AllPropertiesDefault());
+ public static bool AnyEmptyOrNull(this IEnumerable srcs) where T : class => srcs.Any(x => x is null || x.AllPropertiesDefault());
- public static bool AllNotNullAndEmpty(IEnumerable srcs) where T : class => !srcs.Any(x => x is null || x.AllPropertiesDefault());
+ public static bool AllNotEmptyAndNull(this IEnumerable srcs) where T : class => !srcs.Any(x => x is null || x.AllPropertiesDefault());
- public static bool AnyNotNullAndEmpty(IEnumerable srcs) where T : class => srcs.Any(x => x is not null || x.AnyPropertiesNotDefault());
+ public static bool AnyNotEmptyAndNull(this IEnumerable srcs) where T : class => srcs.Any(x => x is not null || x.AnyPropertiesNotDefault());
}
diff --git a/lib/YANLib/YANModel.Property.cs b/lib/YANLib/YANModel.Property.cs
index 4666fa3..27bfdd7 100644
--- a/lib/YANLib/YANModel.Property.cs
+++ b/lib/YANLib/YANModel.Property.cs
@@ -23,7 +23,7 @@ public static bool AllPropertiesNotDefault(this T? mdl) where T : class
return true;
}
- public static bool AllPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault());
+ public static bool AllPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesDefault());
public static bool AllPropertiesDefault(this T? mdl) where T : class
{
@@ -42,7 +42,7 @@ public static bool AllPropertiesDefault(this T? mdl) where T : class
return true;
}
- public static bool AllPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault());
+ public static bool AllPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesNotDefault());
public static bool AnyPropertiesNotDefault(this T? mdl) where T : class
{
@@ -61,7 +61,7 @@ public static bool AnyPropertiesNotDefault(this T? mdl) where T : class
return false;
}
- public static bool AnyPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault());
+ public static bool AnyPropertiesNotDefault(this IEnumerable mdls) where T : class => mdls.IsNotEmptyAndNull() && mdls.Any(x => x.AnyPropertiesNotDefault());
public static bool AnyPropertiesDefault(this T? mdl) where T : class
{
@@ -80,11 +80,11 @@ public static bool AnyPropertiesDefault(this T? mdl) where T : class
return false;
}
- public static bool AnyPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesDefault());
+ public static bool AnyPropertiesDefault(this IEnumerable mdls) where T : class => mdls.IsNotEmptyAndNull() && mdls.Any(x => x.AnyPropertiesDefault());
public static bool AllPropertiesNotDefault(this T? mdl, params string[] names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -99,11 +99,11 @@ public static bool AllPropertiesNotDefault(this T? mdl, params string[] names
return true;
}
- public static bool AllPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault(names));
+ public static bool AllPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesDefault(names));
public static bool AllPropertiesDefault(this T? mdl, params string[] names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -118,11 +118,11 @@ public static bool AllPropertiesDefault(this T? mdl, params string[] names) w
return true;
}
- public static bool AllPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault(names));
+ public static bool AllPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesNotDefault(names));
public static bool AnyPropertiesNotDefault(this T? mdl, params string[] names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -137,11 +137,11 @@ public static bool AnyPropertiesNotDefault(this T? mdl, params string[] names
return false;
}
- public static bool AnyPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault(names));
+ public static bool AnyPropertiesNotDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotEmptyAndNull() && mdls.Any(x => x.AnyPropertiesNotDefault(names));
public static bool AnyPropertiesDefault(this T? mdl, params string[] names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -156,11 +156,11 @@ public static bool AnyPropertiesDefault(this T? mdl, params string[] names) w
return false;
}
- public static bool AnyPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesDefault(names));
+ public static bool AnyPropertiesDefault(this IEnumerable mdls, params string[] names) where T : class => mdls.IsNotEmptyAndNull() && mdls.Any(x => x.AnyPropertiesDefault(names));
public static bool AllPropertiesNotDefault(this T? mdl, IEnumerable names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -175,11 +175,11 @@ public static bool AllPropertiesNotDefault(this T? mdl, IEnumerable n
return true;
}
- public static bool AllPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesDefault(names));
+ public static bool AllPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesDefault(names));
public static bool AllPropertiesDefault(this T? mdl, IEnumerable names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -194,11 +194,11 @@ public static bool AllPropertiesDefault(this T? mdl, IEnumerable name
return true;
}
- public static bool AllPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && !mdls.Any(x => x.AnyPropertiesNotDefault(names));
+ public static bool AllPropertiesDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotEmptyAndNull() && !mdls.Any(x => x.AnyPropertiesNotDefault(names));
public static bool AnyPropertiesNotDefault(this T? mdl, IEnumerable names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -213,11 +213,11 @@ public static bool AnyPropertiesNotDefault(this T? mdl, IEnumerable n
return false;
}
- public static bool AnyPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotNullAndEmpty() && mdls.Any(x => x.AnyPropertiesNotDefault(names));
+ public static bool AnyPropertiesNotDefault(this IEnumerable mdls, IEnumerable names) where T : class => mdls.IsNotEmptyAndNull() && mdls.Any(x => x.AnyPropertiesNotDefault(names));
public static bool AnyPropertiesDefault(this T? mdl, IEnumerable names) where T : class
{
- if (mdl is null || names.AllNullOrWhiteSpace())
+ if (mdl is null || names.AllWhiteSpaceOrNull())
{
return false;
}
@@ -232,5 +232,5 @@ public static bool AnyPropertiesDefault(this T? mdl, IEnumerable name
return false;
}
- public static bool AnyPropertiesDefault