using ScadaLink.CentralUI.Components; namespace ScadaLink.CentralUI.Tests.Monitoring; /// /// Regression tests for CentralUI-008. <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 { [Fact] public void LocalInputToUtc_Null_ReturnsNull() { Assert.Null(BrowserTime.LocalInputToUtc(null, 0)); } [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); } [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); } [Fact] public void LocalInputToUtc_NegativeUtcOffsetBrowser_AddsOffset() { // A browser at UTC-5 (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); } [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); } }