First actual commit
added sources to repository
This commit is contained in:
25
RedditSharp/UnixTimestampConverter.cs
Normal file
25
RedditSharp/UnixTimestampConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace RedditSharp
|
||||
{
|
||||
public class UnixTimestampConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(double) || objectType == typeof(DateTime);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var token = JToken.Load(reader);
|
||||
return token.Value<long>().UnixTimeStampToDateTime();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user