21 lines
703 B
C#
21 lines
703 B
C#
using System;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Pal.Client.Net;
|
|
|
|
public sealed class JwtDateConverter : JsonConverter<DateTimeOffset>
|
|
{
|
|
static readonly DateTimeOffset Zero = new(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
|
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
if (reader.TokenType != JsonTokenType.Number)
|
|
throw new JsonException("bad token type");
|
|
|
|
return Zero.AddSeconds(reader.GetInt64());
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) => throw new NotImplementedException();
|
|
}
|