This repository has been archived on 2024-03-05. You can view files and clone it, but cannot push or open issues or pull requests.
Salesforce.NET/Converters/UnixTimestampDateConverter.cs

27 lines
819 B
C#
Raw Normal View History

2021-04-20 22:10:07 +00:00
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();
}
}