aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Converters/JsonDateTimeConverter.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-11-20 20:11:49 +0800
committerGitHub <noreply@github.com>2019-11-20 20:11:49 +0800
commit1bb9a2a622955e7c0a0b75e36fb1673cb9f3aca5 (patch)
treefb40d254bcec2946ce7c080089c76a342d3472b0 /Timeline/Models/Converters/JsonDateTimeConverter.cs
parentf2ca682f8d111112adc167dcf62011676c3ceb00 (diff)
parent1e86a5c6fbbd6aa05a0a5fcaadf8a9d7b1402eca (diff)
downloadtimeline-1bb9a2a622955e7c0a0b75e36fb1673cb9f3aca5.tar.gz
timeline-1bb9a2a622955e7c0a0b75e36fb1673cb9f3aca5.tar.bz2
timeline-1bb9a2a622955e7c0a0b75e36fb1673cb9f3aca5.zip
Merge pull request #55 from crupest/format
Fix some format problems.
Diffstat (limited to 'Timeline/Models/Converters/JsonDateTimeConverter.cs')
-rw-r--r--Timeline/Models/Converters/JsonDateTimeConverter.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Timeline/Models/Converters/JsonDateTimeConverter.cs b/Timeline/Models/Converters/JsonDateTimeConverter.cs
new file mode 100644
index 00000000..551bbbaa
--- /dev/null
+++ b/Timeline/Models/Converters/JsonDateTimeConverter.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Diagnostics;
+using System.Globalization;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Timeline.Models.Converters
+{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
+ public class JsonDateTimeConverter : JsonConverter<DateTime>
+ {
+ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ Debug.Assert(typeToConvert == typeof(DateTime));
+ return DateTime.Parse(reader.GetString(), CultureInfo.InvariantCulture);
+ }
+
+ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToUniversalTime().ToString("s", CultureInfo.InvariantCulture));
+ }
+ }
+}