You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
using System;
|
|
using System.Data;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Dapper;
|
|
|
|
namespace NzbDrone.Core.Datastore.Converters
|
|
{
|
|
public class DapperUtcConverter : SqlMapper.TypeHandler<DateTime>
|
|
{
|
|
public override void SetValue(IDbDataParameter parameter, DateTime value)
|
|
{
|
|
parameter.Value = value.ToUniversalTime();
|
|
}
|
|
|
|
public override DateTime Parse(object value)
|
|
{
|
|
return DateTime.SpecifyKind((DateTime)value, DateTimeKind.Utc);
|
|
}
|
|
}
|
|
|
|
public class UtcConverter : JsonConverter<DateTime>
|
|
{
|
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
return DateTime.Parse(reader.GetString());
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStringValue(value.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"));
|
|
}
|
|
}
|
|
}
|