-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Majorsoft.Blazor.Components.Notifications/HTML5/EpochTimestampDateTimeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Majorsoft.Blazor.Components.Notifications | ||
{ | ||
internal class EpochTimestampDateTimeConverter : JsonConverter<DateTime> | ||
{ | ||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
long ms = reader.GetInt64(); | ||
return DateTimeOffset.FromUnixTimeMilliseconds(ms).DateTime; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) | ||
{ | ||
long ms = new DateTimeOffset(value).ToUnixTimeMilliseconds(); | ||
writer.WriteNumberValue(ms); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters