I am parsing some interestingly formatted data from https://raw.githubusercontent.com/QuantConnect/Lean/master/Data/market-hours/market-hours-database.json
It contains a snippet (removing some days) as below:
"Future-cme-[*]": {
"dataTimeZone": "UTC",
"exchangeTimeZone": "America/Chicago",
"monday": [
{
"start": "00:00:00",
"end": "1.00:00:00",
"state": "market"
}
],
"friday": [
{
"start": "00:00:00",
"end": "16:00:00",
"state": "market"
}
]
}
I am using a JsonConverter<LocalTime>
to convert the above, and I can parse the friday
properties start
and end
without any issues into a LocalTime
.
However, the dates which this represents as an entire day, i.e. 1.00:00:00
it throws an error on as it is not an ISO format - this opens up questions on my (incorrect!) use of the structures.
Currently I have the format that uses the LocalTime
as below:
public class MarketHoursSegment
{
public LocalTime Start { get; init; }
public LocalTime End { get; init; }
public MarketHoursState State { get; init; }
}
And the formatter:
public class LocalTimeConverter : JsonConverter<LocalTime>
{
public override LocalTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return LocalTimePattern
.GeneralIso
.Parse(reader.GetString())
.GetValueOrThrow();
}
public override void Write(Utf8JsonWriter writer, LocalTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
Is there a preferred way to deal with a LocalTime that represents a 24 hours span?
Would I detect
1:00:00:00
in thereader.GetString()
of the converter, and if so set to 00:00:00 (midnight) and check ifStart == End
then we know it is an entire 24 hour period?Or would it be more correct to have the
Start
as aLocalTime
, and a Duration for the hours (i.e. 24 hours) withEnd => Start + Duration
?