mono datetime offset workaround

pull/130/head
Drewster727 9 years ago
parent 3dbef199aa
commit d370bf62d0

@ -1,4 +1,5 @@
using System;
using System.Linq;
namespace PlexRequests.Helpers
{
@ -6,9 +7,20 @@ namespace PlexRequests.Helpers
{
public static DateTimeOffset OffsetUTCDateTime(DateTime utcDateTime, int minuteOffset)
{
TimeSpan ts = TimeSpan.FromMinutes(-minuteOffset);
return new DateTimeOffset(utcDateTime).ToOffset(ts);
//TimeSpan ts = TimeSpan.FromMinutes(-minuteOffset);
//return new DateTimeOffset(utcDateTime).ToOffset(ts);
// this is a workaround below to work with MONO
var tzi = FindTimeZoneFromOffset(minuteOffset);
var utcOffset = tzi.GetUtcOffset(utcDateTime);
var newDate = utcDateTime + utcOffset;
return new DateTimeOffset(newDate.Ticks, utcOffset);
}
private static TimeZoneInfo FindTimeZoneFromOffset(int minuteOffset)
{
var tzc = TimeZoneInfo.GetSystemTimeZones();
return tzc.FirstOrDefault(x => x.BaseUtcOffset.TotalMinutes == -minuteOffset);
}
}
}

Loading…
Cancel
Save