using ZB.MOM.WW.ScadaBridge.CentralUI.Components; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Monitoring; /// /// Regression tests for the datetime-local conversion. <input type="datetime-local"> /// yields the value the user typed in their browser-local time zone. The /// audit-log filter converted it with new DateTimeOffset(value, TimeSpan.Zero) /// — relabelling the local wall-clock value as UTC, shifting the query window by /// the user's offset. performs the /// correct conversion: it applies the browser offset from getTimezoneOffset(). /// public class BrowserTimeTests { /// Verifies that local input to utc, when null, returns null. [Fact] public void LocalInputToUtc_Null_ReturnsNull() { Assert.Null(BrowserTime.LocalInputToUtc(null, 0)); } /// Verifies that local input to utc, when utc browser, leaves time unchanged. [Fact] public void LocalInputToUtc_UtcBrowser_LeavesTimeUnchanged() { // getTimezoneOffset() == 0 for a UTC browser. var local = new DateTime(2026, 5, 16, 9, 30, 0); var utc = BrowserTime.LocalInputToUtc(local, 0); Assert.Equal(new DateTimeOffset(2026, 5, 16, 9, 30, 0, TimeSpan.Zero), utc); } /// Verifies that local input to utc, when positive utc offset browser, subtracts offset. [Fact] public void LocalInputToUtc_PositiveUtcOffsetBrowser_SubtractsOffset() { // A browser at UTC+2 reports getTimezoneOffset() == -120. // The user typing 09:30 local means 07:30 UTC. var local = new DateTime(2026, 5, 16, 9, 30, 0); var utc = BrowserTime.LocalInputToUtc(local, -120); Assert.Equal(new DateTimeOffset(2026, 5, 16, 7, 30, 0, TimeSpan.Zero), utc); } /// Verifies that local input to utc, when negative utc offset browser, adds offset. [Fact] public void LocalInputToUtc_NegativeUtcOffsetBrowser_AddsOffset() { // A browser at UTC minus 5 hours (US Eastern, standard time) reports getTimezoneOffset() == 300. // The user typing 09:30 local means 14:30 UTC. var local = new DateTime(2026, 5, 16, 9, 30, 0); var utc = BrowserTime.LocalInputToUtc(local, 300); Assert.Equal(new DateTimeOffset(2026, 5, 16, 14, 30, 0, TimeSpan.Zero), utc); } /// Verifies that local input to utc, when non utc browser, does not equal naive relabelling. [Fact] public void LocalInputToUtc_NonUtcBrowser_DoesNotEqualNaiveRelabelling() { // The pre-fix bug: naive new DateTimeOffset(value, TimeSpan.Zero). var local = new DateTime(2026, 5, 16, 9, 30, 0); var naive = new DateTimeOffset(local, TimeSpan.Zero); var correct = BrowserTime.LocalInputToUtc(local, 300); Assert.NotEqual(naive, correct); } }