using System; namespace AsbCloudInfrastructure { public static class DateTimeExtentions { /// /// Приветсти к UTC из времени куста /// /// /// /// public static DateTimeOffset ToUtcDateTimeOffset(this DateTime date, double remoteTimezoneOffsetHours) { if (date == default) return new DateTimeOffset(); var dateUtc = date.Kind switch { DateTimeKind.Local => date.ToUniversalTime(), DateTimeKind.Unspecified => DateTime.SpecifyKind(date.AddHours(-remoteTimezoneOffsetHours), DateTimeKind.Utc), _ => date, }; return new DateTimeOffset(dateUtc); } /// /// Привести ко времени куста из utc /// /// /// /// public static DateTime ToRemoteDateTime(this DateTimeOffset date, double remoteTimezoneOffsetHours) { if (date == default) return new DateTime(0, DateTimeKind.Unspecified); var dateTz = date.ToOffset(TimeSpan.FromHours(remoteTimezoneOffsetHours)); return dateTz.DateTime; } } }