using System; namespace AsbCloudInfrastructure { public static class DateTimeExtentions { /// <summary> /// Приветсти к UTC из времени куста /// </summary> /// <param name="date"></param> /// <param name="remoteTimezoneOffsetHours"></param> /// <returns></returns> 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); } /// <summary> /// Привести ко времени куста из utc /// </summary> /// <param name="date"></param> /// <param name="remoteTimezoneOffsetHours"></param> /// <returns></returns> 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; } } }