diff --git a/DiscordChatExporter.Core.Services/DataService.Parsers.cs b/DiscordChatExporter.Core.Services/DataService.Parsers.cs index d008c11..3207f5c 100644 --- a/DiscordChatExporter.Core.Services/DataService.Parsers.cs +++ b/DiscordChatExporter.Core.Services/DataService.Parsers.cs @@ -118,7 +118,7 @@ namespace DiscordChatExporter.Core.Services var title = json["title"]?.Value(); var description = json["description"]?.Value(); var url = json["url"]?.Value(); - var timestamp = json["timestamp"]?.Value(); + var timestamp = json["timestamp"]?.Value().ToDateTimeOffset(); // Get color var color = json["color"] != null @@ -165,8 +165,8 @@ namespace DiscordChatExporter.Core.Services // Get basic data var id = json["id"].Value(); var channelId = json["channel_id"].Value(); - var timestamp = json["timestamp"].Value(); - var editedTimestamp = json["edited_timestamp"]?.Value(); + var timestamp = json["timestamp"].Value().ToDateTimeOffset(); + var editedTimestamp = json["edited_timestamp"]?.Value()?.ToDateTimeOffset(); var content = json["content"].Value(); var type = (MessageType) json["type"].Value(); diff --git a/DiscordChatExporter.Core.Services/DataService.cs b/DiscordChatExporter.Core.Services/DataService.cs index c6d0f3b..6f0010d 100644 --- a/DiscordChatExporter.Core.Services/DataService.cs +++ b/DiscordChatExporter.Core.Services/DataService.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; @@ -9,7 +8,6 @@ using DiscordChatExporter.Core.Models; using DiscordChatExporter.Core.Services.Exceptions; using DiscordChatExporter.Core.Services.Internal; using Failsafe; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Tyrrrz.Extensions; @@ -66,12 +64,7 @@ namespace DiscordChatExporter.Core.Services var raw = await response.Content.ReadAsStringAsync(); // Parse - using (var reader = new JsonTextReader(new StringReader(raw))) - { - reader.DateParseHandling = DateParseHandling.DateTimeOffset; - - return JToken.Load(reader); - } + return JToken.Parse(raw); } } }); diff --git a/DiscordChatExporter.Core.Services/Internal/Extensions.cs b/DiscordChatExporter.Core.Services/Internal/Extensions.cs index c722bc6..c5d9ec6 100644 --- a/DiscordChatExporter.Core.Services/Internal/Extensions.cs +++ b/DiscordChatExporter.Core.Services/Internal/Extensions.cs @@ -5,11 +5,11 @@ namespace DiscordChatExporter.Core.Services.Internal { internal static class Extensions { - public static string ToSnowflake(this DateTimeOffset date) + public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime) => new DateTimeOffset(dateTime); + + public static string ToSnowflake(this DateTimeOffset dateTime) { - const long epoch = 62135596800000; - var unixTime = date.ToUniversalTime().Ticks / TimeSpan.TicksPerMillisecond - epoch; - var value = ((ulong) unixTime - 1420070400000UL) << 22; + var value = ((ulong) dateTime.ToUnixTimeMilliseconds() - 1420070400000UL) << 22; return value.ToString(); }