diff --git a/Medium/Authentication/Token.cs b/Medium/Authentication/Token.cs index a2744b4..d3201be 100644 --- a/Medium/Authentication/Token.cs +++ b/Medium/Authentication/Token.cs @@ -18,7 +18,7 @@ public class Token public Scope[] Scope { get; set; } [JsonProperty(PropertyName = "expires_at")] - [JsonConverter(typeof(UnixTimestampConverter))] + [JsonConverter(typeof(JsonNetConverters.UnixTime.UnixTimeConverter))] public DateTime ExpiresAt { get; set; } } } \ No newline at end of file diff --git a/Medium/Helpers/Helper.cs b/Medium/Helpers/Helper.cs index 0246af9..5670f01 100644 --- a/Medium/Helpers/Helper.cs +++ b/Medium/Helpers/Helper.cs @@ -165,13 +165,6 @@ public static string GenerateWwwFormUrlEncodedString(Dictionary ConcatenateString("&"); } - // Core.TimeUtilities.cs - public static DateTime? FromUnixTimestampMs(long? timestamp) - { - if (!timestamp.HasValue) return null; - return new DateTime(1970, 1, 1).AddMilliseconds(timestamp.Value); - } - // Core.StringExtensions.cs public static string Replace(this string source, Regex regex, string replacement) { diff --git a/Medium/Helpers/UnixTimestampConverter.cs b/Medium/Helpers/UnixTimestampConverter.cs deleted file mode 100644 index 8a82ca0..0000000 --- a/Medium/Helpers/UnixTimestampConverter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Linq; - -namespace Medium.Helpers -{ - internal class UnixTimestampConverter : JsonConverter - { - private static readonly DateTime _epoch = new DateTime(1970, 1, 1); - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - writer.WriteRawValue(((DateTime)value - _epoch).TotalMilliseconds.ToString()); - } - - public override bool CanConvert(Type objectType) - { - return objectType == new DateTime().GetType(); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var timestamp = reader.Value as long?; - return !timestamp.HasValue ? null : Helper.FromUnixTimestampMs(timestamp); - } - } -} \ No newline at end of file diff --git a/Medium/Medium.csproj b/Medium/Medium.csproj index 7962503..304b73e 100644 --- a/Medium/Medium.csproj +++ b/Medium/Medium.csproj @@ -21,6 +21,7 @@ + diff --git a/Medium/Models/Post.cs b/Medium/Models/Post.cs index d8adf2b..1536010 100644 --- a/Medium/Models/Post.cs +++ b/Medium/Models/Post.cs @@ -14,7 +14,7 @@ public class Post public string Url { get; set; } public string CanonicalUrl { get; set; } public PublishStatus PublishStatus { get; set; } - [JsonConverter(typeof(UnixTimestampConverter))] + [JsonConverter(typeof(JsonNetConverters.UnixTime.UnixTimeConverter))] public DateTime? PublishedAt { get; set; } [JsonConverter(typeof(LicenseEnumConverter))] public License License { get; set; }