toDotNetTicks
Signature
Section titled “Signature”toDotNetTicks(isoString: string): bigintConvert an ISO 8601 instant string to .NET DateTime.Ticks.
- Ticks count 100-nanosecond intervals since 0001-01-01T00:00:00 in the proleptic Gregorian calendar — the same unit as
FILETIME, a different origin. The two differ by504911232000000000n, the tick count at 1601-01-01. - Sub-100 ns digits floor away, toward negative infinity, so the tick grid stays uniform either side of the epoch. Reach for
truncateNanosecondsfirst if the caller needs to see the loss. - The range is
DateTime’s own, and instants outside it are invalid input, not a negative tick count:DateTime.MinValue(0n, 0001-01-01) toDateTime.MaxValue(3155378975999999999n, 9999-12-31T23:59:59.9999999). - The result is a bare tick count, with no
DateTimeKind. .NET stores the kind in the top two bits ofDateTime’s backing field, not inTicks; treat the value as UTC. - Returns
0non invalid input.0nis alsoDateTime.MinValueitself (0001-01-01) — validate the string first withisValidInstantwhen the two must be told apart.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
isoString | string | ISO 8601 instant string (e.g. “2024-03-10T12:00:00Z”) |
Returns
Section titled “Returns”100-nanosecond intervals since 0001-01-01 as a bigint, or 0n on invalid input
Examples
Section titled “Examples”import { toDotNetTicks } from "@northguild/gmt/precision/convert";
toDotNetTicks("0001-01-01T00:00:00Z") // 0n — DateTime.MinValue