public void GetSwatchInternetTime() { var t1 = EssentialsTime.FromUnixTimeSeconds(1605361960); var r1 = (int)SwatchUtils.ToDouble(t1); var t2 = new DateTime(2020, 11, 14, 13, 52, 40, DateTimeKind.Utc); var r2 = (int)SwatchUtils.ToDouble(t2); var t3 = new DateTimeOffset(2020, 11, 14, 14, 52, 40, TimeSpan.FromHours(1)); var r3 = (int)SwatchUtils.ToDouble(t3); var t4 = EssentialsTime.FromUnixTimeSeconds(1597646100); var r4 = (int)SwatchUtils.ToDouble(t4); var t5 = new DateTime(2020, 8, 17, 6, 35, 00, DateTimeKind.Utc); var r5 = (int)SwatchUtils.ToDouble(t5); var t6 = new DateTimeOffset(2020, 8, 17, 8, 35, 00, TimeSpan.FromHours(2)); var r6 = (int)SwatchUtils.ToDouble(t6); Assert.AreEqual(619, r1, "#1"); Assert.AreEqual(619, r2, "#2"); Assert.AreEqual(619, r3, "#3"); Assert.AreEqual(315, r4, "#1"); Assert.AreEqual(315, r5, "#2"); Assert.AreEqual(315, r6, "#3"); }
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { switch (reader.TokenType) { case JsonTokenType.Null: return(null); case JsonTokenType.Number: return(EssentialsTime.FromUnixTimeSeconds(reader.GetInt32())); case JsonTokenType.String: return(EssentialsTime.Parse(reader.GetString())); default: throw new Exception($"Unsupported token type: {reader.TokenType}"); } }