Skip to content

Commit

Permalink
230509
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed May 9, 2023
1 parent 1a99e25 commit d6f3acf
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 350 deletions.
2 changes: 1 addition & 1 deletion lib/YANLib/Nullable/YANDateTime.Nullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static partial class YANDateTime
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.</returns>
public static IEnumerable<DateTime?> ToDateTime(this IEnumerable<string> strs, string fmt, DateTime? dfltVal)
{
if (strs.AllNullOrWhiteSpace())
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/YANLib/Nullable/YANDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static partial class YANDateTime
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string.</returns>
public static IEnumerable<DateTime?> ToDateTime(this IEnumerable<string> strs)
{
if (strs.AllNullOrWhiteSpace())
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ public static partial class YANDateTime
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format.</returns>
public static IEnumerable<DateTime?> ToDateTime(this IEnumerable<string> strs, string fmt)
{
if (strs.AllNullOrWhiteSpace())
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public static partial class YANDateTime
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.</returns>
public static IEnumerable<DateTime?> ToDateTime(this IEnumerable<string> strs, string fmt, DateTime dfltVal)
{
if (strs.AllNullOrWhiteSpace())
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
Expand Down
210 changes: 210 additions & 0 deletions lib/YANLib/Ultimate/YANDateTime.Nullable.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Converts a collection of string representations of dates and times to their <see cref="DateTime"/> equivalents using the specified format.
/// Returns an enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert.
/// </summary>
/// <param name="strs">The collection of strings to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input strings.</param>
/// <param name="dfltVal">The default value to return for any strings that fail to convert.</param>
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.</returns>
public static IEnumerable<DateTime> ToDateTime(this IEnumerable<string> strs, string fmt, DateTime? dfltVal)
{
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
foreach (var str in strs)
{
yield return str.ToDateTime(fmt, dfltVal);
}
}

public static IEnumerable<DateTime> GenerateRandomDateTimes<T>(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<DateTime> GenerateRandomDateTimes<T>(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<DateTime> GenerateRandomDateTimes<T>(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<DateTime> GenerateRandomDateTimes<T>(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<DateTime> GenerateRandomDateTimes<T>(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<DateTime> GenerateRandomDateTimes<T>(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<int> GetWeekOfYear(this IEnumerable<DateTime?> dts)
{
if (dts is null || !dts.Any())
{
yield break;
}
foreach (var dt in dts)
{
yield return dt.GetWeekOfYear();
}
}

public static IEnumerable<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime?> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime?> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime?> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime> 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<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime?> 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<DateTime> ChangeTimeZone<T>(this IEnumerable<DateTime?> 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<DateTime> ChangeTimeZone<T>(this IEnumerable<DateTime> 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<DateTime> ChangeTimeZone<T>(this IEnumerable<DateTime?> dts, T? tzDst) where T : struct
{
if (dts is null || !dts.Any())
{
yield break;
}
foreach (var dt in dts)
{
yield return dt.ChangeTimeZone(tzDst);
}
}
}
105 changes: 105 additions & 0 deletions lib/YANLib/Ultimate/YANDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
namespace YANLib.Ultimate;

public static partial class YANDateTime
{
/// <summary>
/// Converts a collection of string representations of dates and times to their <see cref="DateTime"/> equivalents.
/// Returns an enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string, and skips any strings that fail to convert.
/// </summary>
/// <param name="strs">The collection of strings to be converted to <see cref="DateTime"/>.</param>
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string.</returns>
public static IEnumerable<DateTime> ToDateTime(this IEnumerable<string> strs)
{
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
foreach (var str in strs)
{
yield return str.ToDateTime();
}
}

/// <summary>
/// Converts a collection of string representations of dates and times to their <see cref="DateTime"/> equivalents using the specified format.
/// Returns an enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and skips any strings that fail to convert.
/// </summary>
/// <param name="strs">The collection of strings to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input strings.</param>
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format.</returns>
public static IEnumerable<DateTime> ToDateTime(this IEnumerable<string> strs, string fmt)
{
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
foreach (var str in strs)
{
yield return str.ToDateTime(fmt);
}
}

/// <summary>
/// Converts a collection of string representations of dates and times to their <see cref="DateTime"/> equivalents using the specified format.
/// Returns an enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and returns the specified default value for any strings that fail to convert.
/// </summary>
/// <param name="strs">The collection of strings to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input strings.</param>
/// <param name="dfltVal">The default value to return for any strings that fail to convert.</param>
/// <returns>An enumerable collection of <see cref="DateTime"/> objects for each successfully converted input string in the specified format, and the specified default value for any strings that fail to convert.</returns>
public static IEnumerable<DateTime> ToDateTime(this IEnumerable<string> strs, string fmt, DateTime dfltVal)
{
if (strs.AllWhiteSpaceOrNull())
{
yield break;
}
foreach (var str in strs)
{
yield return str.ToDateTime(fmt, dfltVal);
}
}

public static IEnumerable<DateTime> GenerateRandomDateTimes<T>(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<int> GetWeekOfYear(this IEnumerable<DateTime> dts)
{
if (dts is null || !dts.Any())
{
yield break;
}
foreach (var dt in dts)
{
yield return dt.GetWeekOfYear();
}
}

public static IEnumerable<DateTime> ChangeTimeZone<T1, T2>(this IEnumerable<DateTime> 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<DateTime> ChangeTimeZone<T>(this IEnumerable<DateTime> dts, T tzDst) where T : struct
{
if (dts is null || !dts.Any())
{
yield break;
}
foreach (var dt in dts)
{
yield return dt.ChangeTimeZone(tzDst);
}
}
}
Loading

0 comments on commit d6f3acf

Please sign in to comment.