2023-06-13 15:04:47 +10:00
|
|
|
|
using System.Text.Encodings.Web;
|
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
using System.Text.Unicode;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.DAL.Extensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class GeneralExtesions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Преобразует объект в Json, с учетом Cyrillic
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string? ToJson(this object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-06-21 15:01:29 +10:00
|
|
|
|
return JsonSerializer.Serialize(value, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All, UnicodeRanges.Cyrillic) });
|
2023-06-13 15:04:47 +10:00
|
|
|
|
}
|
|
|
|
|
|
catch// (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// todo: писать лог??? или и так пойдет
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-21 11:09:40 +10:00
|
|
|
|
public static DateTimeOffset EndOfDay(this DateTimeOffset date)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new DateTimeOffset(date.Year, date.Month, date.Day, 23, 59, 59, 999, new TimeSpan(0));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static DateTimeOffset StartOfDay(this DateTimeOffset date)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new DateTimeOffset(date.Year, date.Month, date.Day, 0, 0, 0, 0, new TimeSpan(0));
|
|
|
|
|
|
}
|
2023-06-13 15:04:47 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|