0ffd4bdbea
Comment/XML-doc changes only, no code logic: - strip project-tracking references (WP*, P*-*, row-NN, #NN, Task N) from comments, keeping the explanatory rationale - add missing summaries, <param>, <returns>, <typeparam> and <inheritdoc/> - replace misused <inheritdoc/> with real docs; where <inheritdoc/> was combined with useful remarks, move the rationale into // comments - drop stale replicationActor <param> on DeploymentManagerActor ctor Remaining 5 are false positives (CWE-1236 x2, failures-1, year-0001, M365). Build 0 errors / 0 warnings.
42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Components;
|
|
|
|
/// <summary>
|
|
/// Converts <c><input type="datetime-local"></c> values — which are always
|
|
/// expressed in the user's <i>browser-local</i> time zone — into UTC
|
|
/// <see cref="DateTimeOffset"/>s for querying.
|
|
/// <para>
|
|
/// CLAUDE.md mandates UTC throughout the system, but a <c>datetime-local</c>
|
|
/// value carries no offset, so it must be <i>converted</i> to UTC, not relabelled
|
|
/// as UTC. Relabelling shifts every query window by the
|
|
/// user's offset for any non-UTC browser.
|
|
/// </para>
|
|
/// </summary>
|
|
public static class BrowserTime
|
|
{
|
|
/// <summary>
|
|
/// Converts a browser-local <paramref name="localValue"/> to UTC using the
|
|
/// browser's <c>Date.getTimezoneOffset()</c> result.
|
|
/// </summary>
|
|
/// <param name="localValue">
|
|
/// The wall-clock value from a <c>datetime-local</c> input, or <c>null</c>.
|
|
/// </param>
|
|
/// <param name="browserUtcOffsetMinutes">
|
|
/// The value of JavaScript <c>new Date().getTimezoneOffset()</c>: the number
|
|
/// of minutes that, <b>added</b> to local time, yields UTC. It is positive
|
|
/// for time zones behind UTC (e.g. +300 for five hours behind UTC) and negative for zones
|
|
/// ahead (e.g. -120 for UTC+2).
|
|
/// </param>
|
|
/// <returns>The equivalent instant in UTC, or <c>null</c> when the input is null.</returns>
|
|
public static DateTimeOffset? LocalInputToUtc(DateTime? localValue, int browserUtcOffsetMinutes)
|
|
{
|
|
if (localValue is not { } local)
|
|
return null;
|
|
|
|
// getTimezoneOffset() is defined as (UTC - local) in minutes, so
|
|
// UTC = local + offset.
|
|
var utc = DateTime.SpecifyKind(local, DateTimeKind.Unspecified)
|
|
.AddMinutes(browserUtcOffsetMinutes);
|
|
return new DateTimeOffset(utc, TimeSpan.Zero);
|
|
}
|
|
}
|