Replace pistache solar-server with .net solar api
This commit is contained in:
24
src/Solar.Api/Converters/TimeOnlyConverter.cs
Normal file
24
src/Solar.Api/Converters/TimeOnlyConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Solar.Api.Converters;
|
||||
|
||||
public class TimeOnlyConverter : JsonConverter<TimeOnly>
|
||||
{
|
||||
private const string serializationFormat = "HH:mm";
|
||||
|
||||
public override TimeOnly Read(
|
||||
ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
var value = reader.GetString();
|
||||
return TimeOnly.ParseExact(value!, serializationFormat);
|
||||
}
|
||||
|
||||
public override void Write(
|
||||
Utf8JsonWriter writer,
|
||||
TimeOnly value,
|
||||
JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString(serializationFormat));
|
||||
}
|
||||
Reference in New Issue
Block a user