Skip to content

Commit

Permalink
230118
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Jan 18, 2023
1 parent 63b2e51 commit 56a6a36
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
19 changes: 6 additions & 13 deletions YANLib/YANDateTime.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using static System.Globalization.DateTimeFormatInfo;
using static System.DateTime;
using static System.Globalization.CultureInfo;
using static System.Globalization.DateTimeFormatInfo;
using static System.Globalization.DateTimeStyles;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.DateTime;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Intrinsics.X86;
using static System.Math;

namespace YANLib;

Expand Down Expand Up @@ -77,10 +70,10 @@ public static class YANDateTime
public static DateTime RandomDateTime(DateTime min, DateTime max) => min > max ? Today : min.AddDays(new Random().Next((MaxValue - MinValue).Days));

/// <summary>
/// Get week of year advanced.
/// Returns the week of year that includes the date in the specified <see cref="DateTime"/> value.
/// </summary>
/// <param name="dt">Input datetime.</param>
/// <returns>Number week of year.</returns>
/// <returns>The positive integer that represents the week of the year that includes the date in the <paramref name="dt"/> parameter.</returns>
public static int GetWeekOfYear(this DateTime dt) => CurrentInfo.Calendar.GetWeekOfYear(dt, CurrentInfo.CalendarWeekRule, CurrentInfo.FirstDayOfWeek);

/// <summary>
Expand All @@ -89,5 +82,5 @@ public static class YANDateTime
/// <param name="dt1"></param>
/// <param name="dt2"></param>
/// <returns></returns>
public static int TotalMonths(DateTime dt1, DateTime dt2) => Math.Abs((dt1.Year - dt2.Year) * 12 + dt1.Month - dt2.Month);
public static int TotalMonths(DateTime dt1, DateTime dt2) => Abs((dt1.Year - dt2.Year) * 12 + dt1.Month - dt2.Month);
}
12 changes: 1 addition & 11 deletions YANLib/YANList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ public static class YANList
/// <typeparam name="T">Object type.</typeparam>
/// <param name="list">Input list.</param>
/// <returns>List has item or not.</returns>
public static bool HasItem<T>(this List<T> list)
{
if (list != null)
{
if (list.Count > 0)
{
return true;
}
}
return false;
}
public static bool HasItem<T>(this List<T> list) => list != null && list.Count > 0;

/// <summary>
/// Split list by size.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static decimal ParseDecimal(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="decimal.MinValue"/>.</param>
/// <returns>Decimal random number.</returns>
public static decimal RandomNumberDecimal(decimal max) => max < 0 ? new Random().NextDecimal(decimal.MinValue, max) : new Random().NextDecimal(0, max);
public static decimal RandomNumberDecimal(decimal max)
{
var rnd = new Random();
return max < 0 ? rnd.NextDecimal(decimal.MinValue, max) : rnd.NextDecimal(0, max);
}

/// <summary>
/// Generate random decimal number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static double ParseDouble(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="double.MinValue"/>.</param>
/// <returns>Double random number.</returns>
public static double RandomNumberDouble(double max) => max < 0 ? new Random().NextDouble(double.MinValue, max) : new Random().NextDouble(0, max);
public static double RandomNumberDouble(double max)
{
var rnd = new Random();
return max < 0 ? rnd.NextDouble(double.MinValue, max) : rnd.NextDouble(0, max);
}

/// <summary>
/// Generate random double number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Float.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static float ParseFloat(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="float.MinValue"/>.</param>
/// <returns>Float random number.</returns>
public static float RandomNumberFloat(float max) => max < 0 ? new Random().NextSingle(float.MinValue, max) : new Random().NextSingle(0, max);
public static float RandomNumberFloat(float max)
{
var rnd = new Random();
return max < 0 ? rnd.NextSingle(float.MinValue, max) : rnd.NextSingle(0, max);
}

/// <summary>
/// Generate random float number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Int.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static int ParseInt(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="int.MinValue"/>.</param>
/// <returns>Int random number.</returns>
public static int RandomNumberInt(int max) => max < 0 ? new Random().Next(int.MinValue, max) : new Random().Next(0, max);
public static int RandomNumberInt(int max)
{
var rnd = new Random();
return max < 0 ? rnd.Next(int.MinValue, max) : rnd.Next(0, max);
}

/// <summary>
/// Generate random int number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Nint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static nint ParseNint(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="nint.MinValue"/>.</param>
/// <returns>Nint random number.</returns>
public static nint RandomNumberNint(nint max) => (nint)(max < 0 ? new Random().NextInt64(nint.MinValue, max) : new Random().NextInt64(0, max));
public static nint RandomNumberNint(nint max)
{
var rnd = new Random();
return (nint)(max < 0 ? rnd.NextInt64(nint.MinValue, max) : rnd.NextInt64(0, max));
}

/// <summary>
/// Generate random nint number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Sbyte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static sbyte ParseSbyte(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="sbyte.MinValue"/>.</param>
/// <returns>Sbyte random number.</returns>
public static sbyte RandomNumberSbyte(sbyte max) => (sbyte)(max < 0 ? new Random().Next(sbyte.MinValue, max) : new Random().Next(0, max));
public static sbyte RandomNumberSbyte(sbyte max)
{
var rnd = new Random();
return (sbyte)(max < 0 ? rnd.Next(sbyte.MinValue, max) : rnd.Next(0, max));
}

/// <summary>
/// Generate random sbyte number with min and max value.
Expand Down
6 changes: 5 additions & 1 deletion YANLib/YANNum.Short.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public static short ParseShort(this string str)
/// </summary>
/// <param name="max">The exclusive upper bound of the random number to be generated. <paramref name="max"/> must be greater than or equal to 0. If not, the inclusive lower bound of the random number flexible to <see cref="short.MinValue"/>.</param>
/// <returns>Short random number.</returns>
public static short RandomNumberShort(short max) => (short)(max < 0 ? new Random().Next(short.MinValue, max) : new Random().Next(0, max));
public static short RandomNumberShort(short max)
{
var rnd = new Random();
return (short)(max < 0 ? rnd.Next(short.MinValue, max) : rnd.Next(0, max));
}

/// <summary>
/// Generate random short number with min and max value.
Expand Down

0 comments on commit 56a6a36

Please sign in to comment.