Skip to content

Commit

Permalink
v3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed May 3, 2023
1 parent be6f8e6 commit c50c5dd
Show file tree
Hide file tree
Showing 19 changed files with 546 additions and 441 deletions.
1 change: 1 addition & 0 deletions host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="6.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="6.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="6.0.0" />
Expand Down
15 changes: 9 additions & 6 deletions host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.VirtualFileSystem;
using static System.IO.Path;
using Swashbuckle.AspNetCore.SwaggerUI;

namespace YANLib;

[DependsOn(
typeof(YANLibHttpApiModule),
typeof(YANLibHttpApiModule),
typeof(AbpAutofacModule),
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(YANLibApplicationModule),
Expand Down Expand Up @@ -136,14 +136,16 @@ private static void ConfigureSwaggerServices(ServiceConfigurationContext context
configuration["AuthServer:Authority"],
new Dictionary<string, string>
{
{"YANLib", "YANLib API"}
{"YANLib", "YANLib API"},
{"YANJson", "YANJson API"}
},
options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "YANLib API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.SwaggerDoc("main", new OpenApiInfo { Title = "YANLib API", Version = "main" });
options.SwaggerDoc("json", new OpenApiInfo { Title = "YANJson API", Version = "json" });
options.CustomSchemaIds(type => type.FullName);
options.HideAbpEndpoints();
options.EnableAnnotations();
});
}

Expand Down Expand Up @@ -231,7 +233,8 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseSwagger();
app.UseAbpSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "YANLib API");
c.SwaggerEndpoint("/swagger/main/swagger.json", "YANLib API");
c.SwaggerEndpoint("/swagger/json/swagger.json", "YANJson API");

var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
Expand Down
66 changes: 46 additions & 20 deletions lib/YANLib/Nullable/YANDateTime.Nullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@ namespace YANLib.Nullable;

public static partial class YANDateTime
{

/// <summary>
/// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent using the specified format.
/// Returns the resulting <see cref="DateTime"/> object if the conversion is successful, otherwise returns the specified default value.
/// </summary>
/// <param name="str">The string to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input string.</param>
/// <param name="dfltVal">The default value to return if the conversion fails.</param>
/// <returns>The <see cref="DateTime"/> equivalent of the input string in the specified format, or the specified default value if the conversion fails.</returns>
public static DateTime? ToDateTime(this string str, string fmt, DateTime? dfltVal) => dfltVal.HasValue ? str.ToDateTime(fmt, dfltVal.Value) : default;


/// <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.IsNullOrWhiteSpace())
if (strs.AllNullOrWhiteSpace())
{
yield break;
}
Expand All @@ -20,10 +34,37 @@ public static partial class YANDateTime
}
}


/// <summary>
/// Generates a random <see cref="DateTime"/> object between the specified minimum and maximum values.
/// </summary>
/// <param name="min">The minimum <see cref="DateTime"/> value that can be generated.</param>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the specified minimum and maximum values.</returns>
public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : default;


/// <summary>
/// Generates a random <see cref="DateTime"/> object between the specified minimum and maximum values.
/// </summary>
/// <param name="min">The minimum <see cref="DateTime"/> value that can be generated.</param>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the specified minimum and maximum values.</returns>
public static DateTime? GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default;

/// <summary>
/// Generates a random <see cref="DateTime"/> object between the specified minimum and maximum values.
/// </summary>
/// <param name="min">The minimum <see cref="DateTime"/> value that can be generated.</param>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the specified minimum and maximum values.</returns>
public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max);

/// <summary>
/// Generates a random <see cref="DateTime"/> object between the minimum <see cref="DateTime"/> value and the specified maximum value.
/// </summary>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the minimum <see cref="DateTime"/> value and the specified maximum value.</returns>
public static DateTime? GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default;

public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime? min, DateTime max, T size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -32,7 +73,6 @@ public static partial class YANDateTime
}
}


public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime? min, DateTime max, T? size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -41,10 +81,6 @@ public static partial class YANDateTime
}
}


public static DateTime? GenerateRandomDateTime(DateTime min, DateTime? max) => max.HasValue ? GenerateRandomDateTime(min, max.Value) : default;


public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime min, DateTime? max, T size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -53,7 +89,6 @@ public static partial class YANDateTime
}
}


public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime min, DateTime? max, T? size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -62,10 +97,6 @@ public static partial class YANDateTime
}
}


public static DateTime? GenerateRandomDateTime(DateTime? min, DateTime? max) => min.HasValue ? GenerateRandomDateTime(min.Value, max) : GenerateRandomDateTime(max);


public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime? min, DateTime? max, T size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -74,7 +105,6 @@ public static partial class YANDateTime
}
}


public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime? min, DateTime? max, T? size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -83,10 +113,6 @@ public static partial class YANDateTime
}
}


public static DateTime? GenerateRandomDateTime(DateTime? max) => max.HasValue ? GenerateRandomDateTime(max.Value) : default;


public static int? GetWeekOfYear(this DateTime? dt) => dt.HasValue ? dt.Value.GetWeekOfYear() : default;


Expand Down
82 changes: 64 additions & 18 deletions lib/YANLib/Nullable/YANDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ namespace YANLib.Nullable;

public static partial class YANDateTime
{

/// <summary>
/// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent.
/// Returns the resulting <see cref="DateTime"/> object if the conversion is successful, otherwise returns default.
/// </summary>
/// <param name="str">The string to be converted to <see cref="DateTime"/>.</param>
/// <returns>The <see cref="DateTime"/> equivalent of the input string, or default if the conversion fails.</returns>
public static DateTime? ToDateTime(this string str) => TryParse(str, out var dt) ? dt : default;


/// <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.IsNullOrWhiteSpace())
if (strs.AllNullOrWhiteSpace())
{
yield break;
}
Expand All @@ -25,13 +35,25 @@ public static partial class YANDateTime
}
}


/// <summary>
/// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent using the specified format.
/// Returns the resulting <see cref="DateTime"/> object if the conversion is successful, otherwise returns default.
/// </summary>
/// <param name="str">The string to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input string.</param>
/// <returns>The <see cref="DateTime"/> equivalent of the input string in the specified format, or default if the conversion fails.</returns>
public static DateTime? ToDateTime(this string str, string fmt) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : default;


/// <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.IsNullOrWhiteSpace())
if (strs.AllNullOrWhiteSpace())
{
yield break;
}
Expand All @@ -41,13 +63,27 @@ public static partial class YANDateTime
}
}


/// <summary>
/// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent using the specified format.
/// Returns the resulting <see cref="DateTime"/> object if the conversion is successful, otherwise returns the specified default value.
/// </summary>
/// <param name="str">The string to be converted to <see cref="DateTime"/>.</param>
/// <param name="fmt">The format of the input string.</param>
/// <param name="dfltVal">The default value to return if the conversion fails.</param>
/// <returns>The <see cref="DateTime"/> equivalent of the input string in the specified format, or the specified default value if the conversion fails.</returns>
public static DateTime? ToDateTime(this string str, string fmt, DateTime dfltVal) => TryParseExact(str, fmt, InvariantCulture, None, out var dt) ? dt : dfltVal;


/// <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.IsNullOrWhiteSpace())
if (strs.AllNullOrWhiteSpace())
{
yield break;
}
Expand All @@ -57,10 +93,27 @@ public static partial class YANDateTime
}
}


/// <summary>
/// Generates a random <see cref="DateTime"/> object between the specified minimum and maximum values.
/// </summary>
/// <param name="min">The minimum <see cref="DateTime"/> value that can be generated.</param>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the specified minimum and maximum values.</returns>
public static DateTime? GenerateRandomDateTime(DateTime min, DateTime max) => min > max ? default : min.AddTicks(GenerateRandomLong((max - min).Ticks));


/// <summary>
/// Generates a random <see cref="DateTime"/> object between the minimum value of <see cref="DateTime"/> and maximum value of <see cref="DateTime"/>.
/// </summary>
/// <returns>A randomly generated <see cref="DateTime"/> object between the minimum value of <see cref="DateTime"/> and maximum value of <see cref="DateTime"/>.</returns>
public static DateTime? GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue);

/// <summary>
/// Generates a random <see cref="DateTime"/> object between the minimum <see cref="DateTime"/> value and the specified maximum value.
/// </summary>
/// <param name="max">The maximum <see cref="DateTime"/> value that can be generated.</param>
/// <returns>A randomly generated <see cref="DateTime"/> object between the minimum <see cref="DateTime"/> value and the specified maximum value.</returns>
public static DateTime? GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max);

public static IEnumerable<DateTime?> GenerateRandomDateTimes<T>(DateTime min, DateTime max, T size) where T : struct
{
for (var i = 0ul; i < YANNum.ToUlong(size); i++)
Expand All @@ -69,13 +122,6 @@ public static partial class YANDateTime
}
}


public static DateTime? GenerateRandomDateTime() => GenerateRandomDateTime(MinValue, MaxValue);


public static DateTime? GenerateRandomDateTime(DateTime max) => GenerateRandomDateTime(max > Today ? Today : MinValue, max);


public static int? GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek);


Expand Down
Loading

0 comments on commit c50c5dd

Please sign in to comment.