fix(twincat): TOD write bound, historian note, driver-level refused-write test (#306)

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-08 14:26:32 -04:00
parent 90e3fe1cf7
commit 05ed039c73
4 changed files with 46 additions and 1 deletions
@@ -35,7 +35,7 @@ internal static class TwinCATTemporalCodec
switch (type)
{
case TwinCATDataType.Time or TwinCATDataType.TimeOfDay:
return value switch
var ms = value switch
{
TimeSpan ts => ToUInt(ts.TotalMilliseconds),
DateTime => throw new InvalidCastException($"{type} takes a duration in milliseconds, not a DateTime"),
@@ -43,6 +43,10 @@ internal static class TwinCATTemporalCodec
float f => ToUInt(f),
_ => Convert.ToUInt32(value),
};
// TOD is a time of day: a full day or more is not representable.
if (type == TwinCATDataType.TimeOfDay && ms >= 86_400_000u)
throw new OverflowException($"{ms} ms is not a time of day (< 86 400 000)");
return ms;
case TwinCATDataType.Date or TwinCATDataType.DateTime:
if (value is DateTime dt)
{