forked from ddrilling/AsbCloudServer
30 lines
1008 B
C#
30 lines
1008 B
C#
using System;
|
|
|
|
namespace AsbCloudInfrastructure
|
|
{
|
|
public static class DateTimeExtentions
|
|
{
|
|
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);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|