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)
445
445
return new DateTimeOffset ( date , offset ) . DateTime ;
446
446
}
447
447
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
+
449
462
public static void WriteWcfJsonDate ( TextWriter writer , DateTime dateTime )
450
463
{
451
464
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)
46
46
return ( dateTime . ToStableUniversalTime ( ) . Ticks - UnixEpoch ) / TimeSpan . TicksPerMillisecond ;
47
47
}
48
48
49
- private static TimeZoneInfo LocalTimeZone = TimeZoneInfo . Local ;
50
49
public static long ToUnixTimeMs ( this DateTime dateTime )
51
50
{
52
51
var universal = ToDateTimeSinceUnixEpoch ( dateTime ) ;
@@ -64,7 +63,7 @@ private static TimeSpan ToDateTimeSinceUnixEpoch(this DateTime dateTime)
64
63
if ( dateTime . Kind != DateTimeKind . Utc )
65
64
{
66
65
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 )
68
67
: dateTime . ToStableUniversalTime ( ) ;
69
68
}
70
69
You can’t perform that action at this time.
0 commit comments