27 lines
819 B
C#
27 lines
819 B
C#
using BinaryDad.Extensions;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
using System;
|
|
|
|
namespace Salesforce.NET.Converters
|
|
{
|
|
public class UnixTimestampDateConverter : DateTimeConverterBase
|
|
{
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
{
|
|
if (objectType == typeof(DateTime))
|
|
{
|
|
var milliseconds = reader.Value.To<long>();
|
|
|
|
var offset = DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
|
|
|
|
return offset.DateTime.ToLocalTime();
|
|
}
|
|
|
|
return existingValue;
|
|
}
|
|
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
|
|
}
|
|
}
|