ln.json/ln.json/mapping/JSONTimeSpanMapping.cs

25 lines
733 B
C#

// /**
// * File: JSONTimeSpanConverter.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
namespace ln.json.mapping
{
public class JSONTimeSpanMapping : JSONMapping
{
public JSONTimeSpanMapping()
:base(typeof(TimeSpan))
{
}
public override object FromJson(JSONMapper mapper, JSONValue json) => TimeSpan.FromSeconds((long)(((JSONNumber)json).Decimal));
public override JSONValue ToJson(JSONMapper mapper, object value) => new JSONNumber(((TimeSpan)value).TotalSeconds);
}
}