Skip to content

toFileTime

toFileTime(isoString: string): bigint

Convert an ISO 8601 instant string to a Windows FILETIME.

  • A FILETIME counts 100-nanosecond intervals since 1601-01-01T00:00:00Z. The Unix delta is 11 644 473 600 seconds, i.e. 116444736000000000n ticks.
  • Sub-100 ns digits floor away, toward negative infinity, so the tick grid stays uniform either side of the epoch. Reach for truncateNanoseconds first if the caller needs to see the loss.
  • The range is the format’s own, and instants outside it are invalid input, not a negative tick count. The range is 0n to 2^63 − 1 — 1601-01-01 to +030828-09-14T02:48:05.4775807Z. The struct’s two DWORDs could hold more, but Microsoft’s FileTimeToSystemTime requires a value “less than 0x8000000000000000”, and SetFileTime reserves 2^64 − 1 as a “do not modify” marker. Consumers commonly narrow this further: .NET’s DateTime.FromFileTimeUtc stops at 9999-12-31.
  • Returns 0n on invalid input. 0n is also the FILETIME epoch itself (1601-01-01) — validate the string first with isValidInstant when the two must be told apart.
ParameterTypeDescription
isoStringstringISO 8601 instant string (e.g. “2024-03-10T12:00:00Z”)

100-nanosecond intervals since 1601-01-01 as a bigint, or 0n on invalid input

import { toFileTime } from "@northguild/gmt/precision/convert";
toFileTime("1601-01-01T00:00:00Z") // 0n — the FILETIME epoch
output 

precision/convert/toFileTime.ts