Skip to content

Commit 47b8791

Browse files
committed
Add json converter for date time
1 parent f790f0c commit 47b8791

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using WebUntisAPI.Client.Extensions;
9+
10+
namespace WebUntisAPI.Client.Converter
11+
{
12+
internal class DateJsonConverter : JsonConverter<DateTime>
13+
{
14+
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer)
15+
{
16+
JToken token = JToken.Load(reader);
17+
return new DateTime().FromWebUntisTimeFormat(token.Value<string>(), "000");
18+
}
19+
20+
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer)
21+
{
22+
value.ToWebUntisTimeFormat(out string dateString, out _);
23+
writer.WriteValue(dateString);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)