This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -445,7 +445,20 @@ public static DateTime ParseWcfJsonDate(string wcfJsonDate)
445445 return new DateTimeOffset ( date , offset ) . DateTime ;
446446 }
447447
448- private static TimeZoneInfo LocalTimeZone = TimeZoneInfo . Local ;
448+ public static TimeZoneInfo GetLocalTimeZoneInfo ( )
449+ {
450+ try
451+ {
452+ return TimeZoneInfo . Local ;
453+ }
454+ catch ( Exception )
455+ {
456+ return TimeZoneInfo . Utc ; //Fallback for Mono on Windows.
457+ }
458+ }
459+
460+ internal static TimeZoneInfo LocalTimeZone = GetLocalTimeZoneInfo ( ) ;
461+
449462 public static void WriteWcfJsonDate ( TextWriter writer , DateTime dateTime )
450463 {
451464 if ( JsConfig . AssumeUtc && dateTime . Kind == DateTimeKind . Unspecified )
Original file line number Diff line number Diff line change @@ -46,7 +46,6 @@ public static long ToUnixTimeMsAlt(this DateTime dateTime)
4646 return ( dateTime . ToStableUniversalTime ( ) . Ticks - UnixEpoch ) / TimeSpan . TicksPerMillisecond ;
4747 }
4848
49- private static TimeZoneInfo LocalTimeZone = TimeZoneInfo . Local ;
5049 public static long ToUnixTimeMs ( this DateTime dateTime )
5150 {
5251 var universal = ToDateTimeSinceUnixEpoch ( dateTime ) ;
@@ -64,7 +63,7 @@ private static TimeSpan ToDateTimeSinceUnixEpoch(this DateTime dateTime)
6463 if ( dateTime . Kind != DateTimeKind . Utc )
6564 {
6665 dtUtc = dateTime . Kind == DateTimeKind . Unspecified && dateTime > DateTime . MinValue
67- ? DateTime . SpecifyKind ( dateTime . Subtract ( LocalTimeZone . GetUtcOffset ( dateTime ) ) , DateTimeKind . Utc )
66+ ? DateTime . SpecifyKind ( dateTime . Subtract ( DateTimeSerializer . LocalTimeZone . GetUtcOffset ( dateTime ) ) , DateTimeKind . Utc )
6867 : dateTime . ToStableUniversalTime ( ) ;
6968 }
7069
You can’t perform that action at this time.
0 commit comments