| | | 1 | | using Services.BackgroundJobsServices; |
| | | 2 | | |
| | | 3 | | namespace Services.BitrixStockServices; |
| | | 4 | | |
| | | 5 | | /// <summary>UTC из MySQL/EF → отображение MSK (UTC+3).</summary> |
| | | 6 | | public static class BitrixStockMskDateTime |
| | | 7 | | { |
| | | 8 | | public static DateTime ToMsk(DateTime value) |
| | | 9 | | { |
| | 272 | 10 | | var utc = value.Kind switch |
| | 272 | 11 | | { |
| | 270 | 12 | | DateTimeKind.Utc => value, |
| | 1 | 13 | | DateTimeKind.Local => value.ToUniversalTime(), |
| | 1 | 14 | | _ => DateTime.SpecifyKind(value, DateTimeKind.Utc) |
| | 272 | 15 | | }; |
| | | 16 | | |
| | 272 | 17 | | return TimeZoneInfo.ConvertTimeFromUtc(utc, RussianTimeZoneHelper.Zone); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public static string Format(DateTime value, string format = "dd.MM.yyyy HH:mm") |
| | | 21 | | { |
| | 269 | 22 | | return ToMsk(value).ToString(format); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public static string FormatNow(string format = "dd.MM.yyyy HH:mm") |
| | | 26 | | { |
| | 2 | 27 | | return Format(DateTime.UtcNow, format); |
| | | 28 | | } |
| | | 29 | | } |