40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
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
|
||
{
|
||
return JsonSerializer.Serialize(value, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All, UnicodeRanges.Cyrillic) });
|
||
}
|
||
catch// (Exception ex)
|
||
{
|
||
// todo: писать лог??? или и так пойдет
|
||
return null;
|
||
}
|
||
}
|
||
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));
|
||
}
|
||
}
|
||
}
|