fix(worker): send the Write2/WriteSecured2 time argument as box-local time (#228)
MXAccess reads the VT_DATE time argument of Write2, WriteSecured2 and their bulk forms as box-local time and converts it to UTC itself. The worker passed the proto Timestamp's UTC clock fields (the COM marshaler ignores DateTime.Kind), so on vd03 (UTC-5) a Write2 sent at 01:33:00Z was stored at 06:33:00Z. VariantConverter.ConvertToComTimestamp converts a timestamp_value instant with TimeZoneInfo.ConvertTimeFromUtc into the worker's zone (TimeZoneInfo.Local by default, DST included; an injectable zone for tests). The executor uses it for the time argument only: value conversion is unchanged, and the read direction (MXAccess reports UTC; ToTimestamp treats it as UTC) is unchanged. The one residual loss is MXAccess-side: the repeated fall-back hour cannot be told apart in an offset-less VT_DATE. Tests: VariantConverterTimestampTests (UTC-5, US-Eastern DST both edges, UTC+05:30, UTC, fall-back ambiguity, value path unchanged); the four executor forwarding tests inject a fixed UTC-5 zone; the windev live Write2 smoke now sends a past whole-second timestamp and asserts the stored one when applied. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -119,6 +119,17 @@ default:
|
||||
|
||||
`GetVariantTypeName` maps CLR types to canonical `VT_*` strings (`VT_BOOL`, `VT_I4`, `VT_BSTR`, `VT_DATE`, and so on). Unmapped CLR types fall back to `CLR:<FullName>` so the wire format never silently invents a `VT_*` tag it cannot justify. Array element tags are wrapped as `SAFEARRAY(<element>)` by `CreateArrayVariantType`.
|
||||
|
||||
### Timestamps: the two directions differ
|
||||
|
||||
MXAccess does not use one time convention for both directions, so the worker does not either.
|
||||
|
||||
- **Read (OnDataChange source timestamps, `VT_DATE` values).** MXAccess hands the worker UTC clock fields. `ToTimestamp` treats an unspecified-kind `DateTime` as UTC and converts a local-kind one with `ToUniversalTime`. A plain `Write` on vd03 (UTC-5) reports the current UTC time as its source timestamp, which confirms this.
|
||||
- **Write time argument (`Write2`, `WriteSecured2`, `Write2Bulk`, `WriteSecured2Bulk`).** MXAccess reads the `VT_DATE` time argument as **box-local** time and converts it to UTC itself. A `VT_DATE` has no offset field, and the COM marshaler ignores `DateTime.Kind`, so passing the UTC clock fields stored the source timestamp shifted by the box's UTC offset. On vd03 a `Write2` sent at `01:33:00Z` was stored at `06:33:00Z` (#228). `ConvertToComTimestamp` therefore converts the `timestamp_value` instant with `TimeZoneInfo.ConvertTimeFromUtc` into the worker box's zone (`TimeZoneInfo.Local`, DST rules included) before the COM call. The command executor uses it for the time argument only; `ConvertToComValue` still renders a timestamp *value* as UTC, because whether a `Time`-typed attribute value write follows the same rule has not been proven.
|
||||
|
||||
UTC to local is always defined: every UTC instant has exactly one local wall-clock time, and the conversion never produces a local time that does not exist (the skipped spring-forward hour). The one loss is on the MXAccess side. In the hour that repeats when DST ends, two UTC instants an hour apart share one local wall-clock time, and the offset-less `VT_DATE` cannot say which one is meant, so MXAccess may store an instant from that hour 1 h off. Run the worker box on UTC if exact timestamps across the fall-back hour matter. On a UTC box the conversion is the identity, which is why #228 could not be seen there.
|
||||
|
||||
A time argument of another kind (a string or a number) carries no zone and is passed through unchanged; its meaning is the caller's. Consumers must send `timestamp_value` as a UTC instant, as the proto `Timestamp` already is.
|
||||
|
||||
### Why lossless preservation matters
|
||||
|
||||
The MXAccess engine returns values whose semantic type only fully resolves after consulting the engine's own attribute metadata. Clients that round-trip these values through the gateway (replay, parity fixtures, diagnostics) need the original `VT_*` tag, the engine-declared `MxDataType`, and any conversion diagnostic; otherwise edge cases such as decimal-to-double rounding, ulong overflow, or an unknown SAFEARRAY element type become invisible bugs. Storing both the typed projection and the raw fields in the same `MxValue`/`MxArray` lets cross-language clients recover the original observation byte-for-byte where possible and detect lossy cases where it is not.
|
||||
|
||||
Reference in New Issue
Block a user