Added epoch time converter.
This commit is contained in:
parent
bd85216992
commit
62586014bd
@ -74,4 +74,37 @@ namespace SteamStorefrontAPI.Classes
|
||||
}
|
||||
}
|
||||
|
||||
// Converts an epoch string to a datetime object
|
||||
internal class EpochToDateTimeConverter : JsonConverter
|
||||
{
|
||||
public override bool CanRead
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null) return null;
|
||||
var value = serializer.Deserialize<string>(reader);
|
||||
|
||||
long parsedValue;
|
||||
if (long.TryParse(value, out parsedValue))
|
||||
{
|
||||
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(parsedValue);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ namespace SteamStorefrontAPI.Classes
|
||||
public string HeaderImage { get; set; }
|
||||
|
||||
[JsonProperty("discount_expiration", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public long? DiscountExpiration { get; set; }
|
||||
[JsonConverter(typeof(EpochToDateTimeConverter))]
|
||||
public DateTime? DiscountExpiration { get; set; }
|
||||
|
||||
[JsonProperty("controller_support", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(ControllerSupportConverter))]
|
||||
|
Loading…
Reference in New Issue
Block a user