fix(worker): wnwrap alarm DATE+TIME are UTC; stop re-applying GMTOFFSET (#226)
ci / nightly-windev (push) Has been skipped
ci / windows-x86 (push) Successful in 1m26s
ci / java (push) Successful in 2m28s
ci / portable (push) Failing after 3m38s

QueryActiveAlarms / alarm transitions reported every wnwrap alarm late by
the record's GMTOFFSET-DSTADJUST: ParseTransitionTimestampUtc treated the
XML DATE+TIME as producer-local and added the offset, but the fields are
already UTC. DEV evidence: RuntimeAlert raise EventTimeUtc 2026-07-28
20:02:46.830 (EventTimeUTCOffsetMins -300) surfaced as 2026-07-29
01:02:46.830Z. The 2026-05-01 probe capture (TIME 13:26:14.709,
GMTOFFSET 240) was committed at 09:44 EDT, so its TIME is UTC too.

GMTOFFSET/DSTADJUST are no longer read. Tests updated + #226 regressions.
This commit is contained in:
Joseph Doherty
2026-11-12 07:20:44 -05:00
parent 2b13564e04
commit 892bdc1a19
6 changed files with 91 additions and 56 deletions
@@ -118,23 +118,34 @@ public sealed class AlarmRecordTransitionMapperTests
}
}
/// <summary>Verifies that valid XML fields assemble into correct UTC timestamp.</summary>
/// <summary>
/// Verifies that DATE + TIME are taken as UTC as delivered (mxaccessgw#226).
/// Captured payload from the 2026-05-01 dev-rig probe (TIME 13:26:14.709,
/// GMTOFFSET=240): the capture was committed at 09:44 EDT that day, so the
/// wire TIME is UTC; applying GMTOFFSET again would make it 17:26.
/// </summary>
[Fact]
public void ParseTransitionTimestampUtc_WithValidXmlFields_AssemblesUtc()
public void ParseTransitionTimestampUtc_WithValidXmlFields_ReturnsTheWireTimeAsUtc()
{
// Captured payload from probe (2026-05-01): EDT producer, GMTOFFSET=240, DSTADJUST=0.
// Local 13:26:14.709 + 240 minutes (4h) = 17:26:14.709 UTC.
DateTime utc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
"2026/5/1", "13:26:14.709", gmtOffsetMinutes: 240, dstAdjustMinutes: 0);
DateTime utc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("2026/5/1", "13:26:14.709");
Assert.Equal(DateTimeKind.Utc, utc.Kind);
Assert.Equal(2026, utc.Year);
Assert.Equal(5, utc.Month);
Assert.Equal(1, utc.Day);
Assert.Equal(17, utc.Hour);
Assert.Equal(26, utc.Minute);
Assert.Equal(14, utc.Second);
Assert.Equal(709, utc.Millisecond);
Assert.Equal(new DateTime(2026, 5, 1, 13, 26, 14, 709, DateTimeKind.Utc), utc);
}
/// <summary>
/// Regression for mxaccessgw#226: the DEV RuntimeAlert raise is
/// EventTimeUtc 2026-07-28 20:02:46.830 in AVEVA history; the gateway used
/// to report 2026-07-29 01:02:46.830Z (the record's GMTOFFSET of 300 added
/// a second time). Unpadded wnwrap formatting is used on purpose.
/// </summary>
[Fact]
public void ParseTransitionTimestampUtc_Issue226DevRecord_MatchesHistoryUtc()
{
DateTime utc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("2026/7/28", "20:2:46.830");
Assert.Equal(new DateTime(2026, 7, 28, 20, 2, 46, 830, DateTimeKind.Utc), utc);
Assert.NotEqual(new DateTime(2026, 7, 29, 1, 2, 46, 830, DateTimeKind.Utc), utc);
}
/// <summary>Verifies that unparseable inputs return DateTime.MinValue.</summary>
@@ -142,10 +153,10 @@ public sealed class AlarmRecordTransitionMapperTests
public void ParseTransitionTimestampUtc_WithUnparseableInputs_ReturnsMinValue()
{
Assert.Equal(DateTime.MinValue,
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(null, null, 0, 0));
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(null, null));
Assert.Equal(DateTime.MinValue,
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("not a date", "13:00:00", 0, 0));
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("not a date", "13:00:00"));
Assert.Equal(DateTime.MinValue,
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("2026/5/1", "not a time", 0, 0));
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("2026/5/1", "not a time"));
}
}
@@ -253,8 +253,6 @@ public sealed class WnWrapAlarmConsumerXmlParityTests
string? guidHex = null;
string? xmlDate = null;
string? xmlTime = null;
string? gmtOffset = null;
string? dstAdjust = null;
string? providerNode = null;
string? providerName = null;
string? group = null;
@@ -281,8 +279,6 @@ public sealed class WnWrapAlarmConsumerXmlParityTests
case "GUID": guidHex ??= child.InnerText; break;
case "DATE": xmlDate ??= child.InnerText; break;
case "TIME": xmlTime ??= child.InnerText; break;
case "GMTOFFSET": gmtOffset ??= child.InnerText; break;
case "DSTADJUST": dstAdjust ??= child.InnerText; break;
case "PROVIDER_NODE": providerNode ??= child.InnerText; break;
case "PROVIDER_NAME": providerName ??= child.InnerText; break;
case "GROUP": group ??= child.InnerText; break;
@@ -306,9 +302,7 @@ public sealed class WnWrapAlarmConsumerXmlParityTests
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
xmlDate ?? string.Empty,
xmlTime ?? string.Empty,
LegacyParseInt(gmtOffset ?? string.Empty),
LegacyParseInt(dstAdjust ?? string.Empty));
xmlTime ?? string.Empty);
records[guid] = new MxAlarmSnapshotRecord
{
@@ -73,9 +73,31 @@ public sealed class WnWrapAlarmConsumerXmlTests
Assert.Equal(MxAlarmStateKind.UnackAlm, record.State);
Assert.Equal("Test alarm #1", record.AlarmComment);
Assert.Equal(DateTimeKind.Utc, record.TransitionTimestampUtc.Kind);
// 13:26:14.709 EDT (UTC-4, DSTADJUST=0) + 240 minutes = 17:26:14.709 UTC.
Assert.Equal(17, record.TransitionTimestampUtc.Hour);
Assert.Equal(26, record.TransitionTimestampUtc.Minute);
// DATE + TIME are UTC on the wire; GMTOFFSET=240 is informational and
// must not be applied a second time (mxaccessgw#226).
Assert.Equal(new DateTime(2026, 5, 1, 13, 26, 14, 709, DateTimeKind.Utc), record.TransitionTimestampUtc);
}
/// <summary>
/// Verifies the GMTOFFSET / DSTADJUST fields never move the parsed
/// timestamp (mxaccessgw#226: a record carrying GMTOFFSET=300 surfaced
/// 5 h late on DEV).
/// </summary>
[Theory]
[InlineData("240", "0")]
[InlineData("300", "0")]
[InlineData("300", "60")]
[InlineData("0", "0")]
[InlineData("-60", "-60")]
public void ParseSnapshotXml_GmtOffsetAndDstAdjust_DoNotShiftTimestamp(string gmtOffset, string dstAdjust)
{
string xml = SingleAlarmActiveXml.Replace(
"<GMTOFFSET>240</GMTOFFSET><DSTADJUST>0</DSTADJUST>",
"<GMTOFFSET>" + gmtOffset + "</GMTOFFSET><DSTADJUST>" + dstAdjust + "</DSTADJUST>");
var record = Assert.Single(WnWrapAlarmConsumer.ParseSnapshotXml(xml).Values);
Assert.Equal(new DateTime(2026, 5, 1, 13, 26, 14, 709, DateTimeKind.Utc), record.TransitionTimestampUtc);
}
/// <summary>Verifies that invalid GUIDs in XML payload are silently dropped.</summary>
@@ -116,23 +116,37 @@ public static class AlarmRecordTransitionMapper
}
/// <summary>
/// Reassemble a UTC <see cref="DateTime"/> from the wnwrap XML's
/// <c>DATE</c> + <c>TIME</c> + <c>GMTOFFSET</c> + <c>DSTADJUST</c>
/// fields. Returns <see cref="DateTime.MinValue"/> when DATE / TIME
/// can't be parsed (best-effort — failure is non-fatal; the proto
/// will carry the epoch and the EventQueue's fault counter records
/// the parse miss).
/// Reassemble the UTC <see cref="DateTime"/> carried by the wnwrap
/// XML's <c>DATE</c> + <c>TIME</c> fields. Returns
/// <see cref="DateTime.MinValue"/> when DATE / TIME can't be parsed
/// (best-effort — failure is non-fatal; the proto will carry the epoch
/// and the EventQueue's fault counter records the parse miss).
/// </summary>
/// <remarks>
/// <para>
/// <c>DATE</c> + <c>TIME</c> are already UTC. The sibling
/// <c>GMTOFFSET</c> / <c>DSTADJUST</c> fields describe the
/// producer's local zone (informational only) and must NOT be
/// applied again — doing so shifted every alarm timestamp late by
/// the producer's offset (mxaccessgw#226: +5 h on DEV for a record
/// carrying <c>GMTOFFSET=300</c>, +4 h for the usual <c>240</c>).
/// </para>
/// <para>
/// Evidence: the 2026-05-01 dev-rig capture (<c>TIME 13:26:14.709</c>,
/// <c>GMTOFFSET=240</c>) was committed at 09:44 EDT that morning, so
/// 13:26 can only be UTC (09:26 EDT); and on wonder-sql-vd03 the
/// <c>CVDAisle_1.TableAlarms_008.RuntimeAlert</c> raise is
/// <c>EventTimeUtc 2026-07-28 20:02:46.830</c> with
/// <c>EventTimeUTCOffsetMins -300</c>, which the old
/// "local + offset" rule turned into <c>2026-07-29 01:02:46.830Z</c>.
/// </para>
/// </remarks>
/// <param name="xmlDate">e.g. <c>"2026/5/1"</c> (no zero-padding).</param>
/// <param name="xmlTime">e.g. <c>"13:26:14.709"</c>.</param>
/// <param name="gmtOffsetMinutes">Offset of the producer's local time vs UTC, in minutes.</param>
/// <param name="dstAdjustMinutes">DST adjustment already applied to local time, in minutes.</param>
/// <returns>The reassembled UTC timestamp, or <see cref="DateTime.MinValue"/> when parsing fails.</returns>
/// <param name="xmlTime">e.g. <c>"13:26:14.709"</c> (UTC).</param>
/// <returns>The UTC timestamp, or <see cref="DateTime.MinValue"/> when parsing fails.</returns>
public static DateTime ParseTransitionTimestampUtc(
string? xmlDate,
string? xmlTime,
int gmtOffsetMinutes,
int dstAdjustMinutes)
string? xmlTime)
{
if (string.IsNullOrWhiteSpace(xmlDate) || string.IsNullOrWhiteSpace(xmlTime))
{
@@ -189,16 +203,11 @@ public static class AlarmRecordTransitionMapper
}
}
DateTime localProducerTime = new DateTime(
// DATE + TIME are UTC as delivered; GMTOFFSET / DSTADJUST are not
// applied (see remarks, mxaccessgw#226).
return new DateTime(
date.Year, date.Month, date.Day,
time.Hour, time.Minute, time.Second, time.Millisecond,
DateTimeKind.Unspecified);
// GMTOFFSET = minutes east of UTC (or behind, depending on convention).
// The wnwrap convention observed: GMTOFFSET=240, DSTADJUST=0 for
// EDT (4 hours behind UTC) — so the field is "minutes from local to UTC". To get
// UTC, ADD the offset.
DateTime utc = localProducerTime.AddMinutes(gmtOffsetMinutes - dstAdjustMinutes);
return DateTime.SpecifyKind(utc, DateTimeKind.Utc);
DateTimeKind.Utc);
}
}
@@ -757,8 +757,6 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
string? guidHex = null;
string? xmlDate = null;
string? xmlTime = null;
string? gmtOffset = null;
string? dstAdjust = null;
string? providerNode = null;
string? providerName = null;
string? group = null;
@@ -791,8 +789,6 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
case "GUID": guidHex ??= text; break;
case "DATE": xmlDate ??= text; break;
case "TIME": xmlTime ??= text; break;
case "GMTOFFSET": gmtOffset ??= text; break;
case "DSTADJUST": dstAdjust ??= text; break;
case "PROVIDER_NODE": providerNode ??= text; break;
case "PROVIDER_NAME": providerName ??= text; break;
case "GROUP": group ??= text; break;
@@ -817,9 +813,7 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
xmlDate ?? string.Empty,
xmlTime ?? string.Empty,
ParseInt(gmtOffset ?? string.Empty),
ParseInt(dstAdjust ?? string.Empty));
xmlTime ?? string.Empty);
records[guid] = new MxAlarmSnapshotRecord
{