fix(worker): wnwrap alarm DATE+TIME are UTC; stop re-applying GMTOFFSET (#226)
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:
@@ -677,7 +677,12 @@ alarm-consumer surface unblocks A.2 fully. Outline:
|
|||||||
`ACK_RTN` → in_alarm=false, acked=true).
|
`ACK_RTN` → in_alarm=false, acked=true).
|
||||||
- `DATE + TIME + GMTOFFSET + DSTADJUST` → reassemble UTC
|
- `DATE + TIME + GMTOFFSET + DSTADJUST` → reassemble UTC
|
||||||
timestamp; matches the worker's existing `Timestamp`
|
timestamp; matches the worker's existing `Timestamp`
|
||||||
wire format.
|
wire format. *Corrected 2026-11-12 (#226): `DATE` + `TIME`
|
||||||
|
are already UTC — the 13:26:14.709 capture above was taken
|
||||||
|
at 09:26 EDT — and `GMTOFFSET`/`DSTADJUST` only describe the
|
||||||
|
producer's zone. Adding the offset made every alarm
|
||||||
|
timestamp late by it (+5 h on DEV for a `GMTOFFSET=300`
|
||||||
|
record).*
|
||||||
- `PRIORITY` → severity (already 1-1000-ish range).
|
- `PRIORITY` → severity (already 1-1000-ish range).
|
||||||
- `TAGNAME` → reference; `PROVIDER_NAME` + `GROUP` for
|
- `TAGNAME` → reference; `PROVIDER_NAME` + `GROUP` for
|
||||||
scope metadata.
|
scope metadata.
|
||||||
|
|||||||
@@ -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]
|
[Fact]
|
||||||
public void ParseTransitionTimestampUtc_WithValidXmlFields_AssemblesUtc()
|
public void ParseTransitionTimestampUtc_WithValidXmlFields_ReturnsTheWireTimeAsUtc()
|
||||||
{
|
{
|
||||||
// Captured payload from probe (2026-05-01): EDT producer, GMTOFFSET=240, DSTADJUST=0.
|
DateTime utc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc("2026/5/1", "13:26:14.709");
|
||||||
// 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);
|
|
||||||
|
|
||||||
Assert.Equal(DateTimeKind.Utc, utc.Kind);
|
Assert.Equal(DateTimeKind.Utc, utc.Kind);
|
||||||
Assert.Equal(2026, utc.Year);
|
Assert.Equal(new DateTime(2026, 5, 1, 13, 26, 14, 709, DateTimeKind.Utc), utc);
|
||||||
Assert.Equal(5, utc.Month);
|
}
|
||||||
Assert.Equal(1, utc.Day);
|
|
||||||
Assert.Equal(17, utc.Hour);
|
/// <summary>
|
||||||
Assert.Equal(26, utc.Minute);
|
/// Regression for mxaccessgw#226: the DEV RuntimeAlert raise is
|
||||||
Assert.Equal(14, utc.Second);
|
/// EventTimeUtc 2026-07-28 20:02:46.830 in AVEVA history; the gateway used
|
||||||
Assert.Equal(709, utc.Millisecond);
|
/// 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>
|
/// <summary>Verifies that unparseable inputs return DateTime.MinValue.</summary>
|
||||||
@@ -142,10 +153,10 @@ public sealed class AlarmRecordTransitionMapperTests
|
|||||||
public void ParseTransitionTimestampUtc_WithUnparseableInputs_ReturnsMinValue()
|
public void ParseTransitionTimestampUtc_WithUnparseableInputs_ReturnsMinValue()
|
||||||
{
|
{
|
||||||
Assert.Equal(DateTime.MinValue,
|
Assert.Equal(DateTime.MinValue,
|
||||||
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(null, null, 0, 0));
|
AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(null, null));
|
||||||
Assert.Equal(DateTime.MinValue,
|
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,
|
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? guidHex = null;
|
||||||
string? xmlDate = null;
|
string? xmlDate = null;
|
||||||
string? xmlTime = null;
|
string? xmlTime = null;
|
||||||
string? gmtOffset = null;
|
|
||||||
string? dstAdjust = null;
|
|
||||||
string? providerNode = null;
|
string? providerNode = null;
|
||||||
string? providerName = null;
|
string? providerName = null;
|
||||||
string? group = null;
|
string? group = null;
|
||||||
@@ -281,8 +279,6 @@ public sealed class WnWrapAlarmConsumerXmlParityTests
|
|||||||
case "GUID": guidHex ??= child.InnerText; break;
|
case "GUID": guidHex ??= child.InnerText; break;
|
||||||
case "DATE": xmlDate ??= child.InnerText; break;
|
case "DATE": xmlDate ??= child.InnerText; break;
|
||||||
case "TIME": xmlTime ??= 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_NODE": providerNode ??= child.InnerText; break;
|
||||||
case "PROVIDER_NAME": providerName ??= child.InnerText; break;
|
case "PROVIDER_NAME": providerName ??= child.InnerText; break;
|
||||||
case "GROUP": group ??= child.InnerText; break;
|
case "GROUP": group ??= child.InnerText; break;
|
||||||
@@ -306,9 +302,7 @@ public sealed class WnWrapAlarmConsumerXmlParityTests
|
|||||||
|
|
||||||
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
|
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
|
||||||
xmlDate ?? string.Empty,
|
xmlDate ?? string.Empty,
|
||||||
xmlTime ?? string.Empty,
|
xmlTime ?? string.Empty);
|
||||||
LegacyParseInt(gmtOffset ?? string.Empty),
|
|
||||||
LegacyParseInt(dstAdjust ?? string.Empty));
|
|
||||||
|
|
||||||
records[guid] = new MxAlarmSnapshotRecord
|
records[guid] = new MxAlarmSnapshotRecord
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,9 +73,31 @@ public sealed class WnWrapAlarmConsumerXmlTests
|
|||||||
Assert.Equal(MxAlarmStateKind.UnackAlm, record.State);
|
Assert.Equal(MxAlarmStateKind.UnackAlm, record.State);
|
||||||
Assert.Equal("Test alarm #1", record.AlarmComment);
|
Assert.Equal("Test alarm #1", record.AlarmComment);
|
||||||
Assert.Equal(DateTimeKind.Utc, record.TransitionTimestampUtc.Kind);
|
Assert.Equal(DateTimeKind.Utc, record.TransitionTimestampUtc.Kind);
|
||||||
// 13:26:14.709 EDT (UTC-4, DSTADJUST=0) + 240 minutes = 17:26:14.709 UTC.
|
// DATE + TIME are UTC on the wire; GMTOFFSET=240 is informational and
|
||||||
Assert.Equal(17, record.TransitionTimestampUtc.Hour);
|
// must not be applied a second time (mxaccessgw#226).
|
||||||
Assert.Equal(26, record.TransitionTimestampUtc.Minute);
|
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>
|
/// <summary>Verifies that invalid GUIDs in XML payload are silently dropped.</summary>
|
||||||
|
|||||||
@@ -116,23 +116,37 @@ public static class AlarmRecordTransitionMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reassemble a UTC <see cref="DateTime"/> from the wnwrap XML's
|
/// Reassemble the UTC <see cref="DateTime"/> carried by the wnwrap
|
||||||
/// <c>DATE</c> + <c>TIME</c> + <c>GMTOFFSET</c> + <c>DSTADJUST</c>
|
/// XML's <c>DATE</c> + <c>TIME</c> fields. Returns
|
||||||
/// fields. Returns <see cref="DateTime.MinValue"/> when DATE / TIME
|
/// <see cref="DateTime.MinValue"/> when DATE / TIME can't be parsed
|
||||||
/// can't be parsed (best-effort — failure is non-fatal; the proto
|
/// (best-effort — failure is non-fatal; the proto will carry the epoch
|
||||||
/// will carry the epoch and the EventQueue's fault counter records
|
/// and the EventQueue's fault counter records the parse miss).
|
||||||
/// the parse miss).
|
|
||||||
/// </summary>
|
/// </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="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="xmlTime">e.g. <c>"13:26:14.709"</c> (UTC).</param>
|
||||||
/// <param name="gmtOffsetMinutes">Offset of the producer's local time vs UTC, in minutes.</param>
|
/// <returns>The UTC timestamp, or <see cref="DateTime.MinValue"/> when parsing fails.</returns>
|
||||||
/// <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>
|
|
||||||
public static DateTime ParseTransitionTimestampUtc(
|
public static DateTime ParseTransitionTimestampUtc(
|
||||||
string? xmlDate,
|
string? xmlDate,
|
||||||
string? xmlTime,
|
string? xmlTime)
|
||||||
int gmtOffsetMinutes,
|
|
||||||
int dstAdjustMinutes)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(xmlDate) || string.IsNullOrWhiteSpace(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,
|
date.Year, date.Month, date.Day,
|
||||||
time.Hour, time.Minute, time.Second, time.Millisecond,
|
time.Hour, time.Minute, time.Second, time.Millisecond,
|
||||||
DateTimeKind.Unspecified);
|
DateTimeKind.Utc);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -757,8 +757,6 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
|||||||
string? guidHex = null;
|
string? guidHex = null;
|
||||||
string? xmlDate = null;
|
string? xmlDate = null;
|
||||||
string? xmlTime = null;
|
string? xmlTime = null;
|
||||||
string? gmtOffset = null;
|
|
||||||
string? dstAdjust = null;
|
|
||||||
string? providerNode = null;
|
string? providerNode = null;
|
||||||
string? providerName = null;
|
string? providerName = null;
|
||||||
string? group = null;
|
string? group = null;
|
||||||
@@ -791,8 +789,6 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
|||||||
case "GUID": guidHex ??= text; break;
|
case "GUID": guidHex ??= text; break;
|
||||||
case "DATE": xmlDate ??= text; break;
|
case "DATE": xmlDate ??= text; break;
|
||||||
case "TIME": xmlTime ??= 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_NODE": providerNode ??= text; break;
|
||||||
case "PROVIDER_NAME": providerName ??= text; break;
|
case "PROVIDER_NAME": providerName ??= text; break;
|
||||||
case "GROUP": group ??= text; break;
|
case "GROUP": group ??= text; break;
|
||||||
@@ -817,9 +813,7 @@ public sealed class WnWrapAlarmConsumer : IMxAccessAlarmConsumer
|
|||||||
|
|
||||||
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
|
DateTime tsUtc = AlarmRecordTransitionMapper.ParseTransitionTimestampUtc(
|
||||||
xmlDate ?? string.Empty,
|
xmlDate ?? string.Empty,
|
||||||
xmlTime ?? string.Empty,
|
xmlTime ?? string.Empty);
|
||||||
ParseInt(gmtOffset ?? string.Empty),
|
|
||||||
ParseInt(dstAdjust ?? string.Empty));
|
|
||||||
|
|
||||||
records[guid] = new MxAlarmSnapshotRecord
|
records[guid] = new MxAlarmSnapshotRecord
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user