Skip to content

utcToPtp

  • Device and sensor time on industrial networks: Precision Time Protocol timestamps, which count TAI, and the UTC offset a grandmaster announces.
utcToPtp(value: string, currentUtcOffset: number): PtpTimestamp | null

Converts a UTC instant to the PTP (IEEE 1588) timestamp a grandmaster announcing currentUtcOffset would send.

  • The result is the instant’s seconds since 1970-01-01T00:00:00Z plus the offset, counted as TAI from 1970-01-01T00:00:00 TAI. It is the inverse of ptpToUtc for the same offset.
  • currentUtcOffset is TAI − UTC as announced. It is required, has no default, and must be an integer from −32 768 to 32 767. The same ptpTimescale and currentUtcOffsetValid preconditions as ptpToUtc apply: call it only when the grandmaster announces both as true.
  • Accepts Z or a numeric offset (2024-01-01T02:00:00+02:00). An offset-less string, a zone or calendar annotation, and a second of 60 return null. With one offset for the whole call, an inserted second has no reading of its own.
  • seconds comes back as a bigint, and every nanosecond written in the input is kept.
  • Returns null for an instant before 1970-01-01T00:00:00Z, which ptpToUtc would refuse, and for a result below 0 seconds. It never throws.
ParameterTypeDescription
valuestringISO 8601 instant string with Z or a numeric offset
currentUtcOffsetnumberTAI − UTC in seconds, as announced: an integer from -32768 to 32767

the { seconds, nanoseconds } record, or null on invalid input

import { utcToPtp } from "@northguild/gmt/iot/convert";
utcToPtp("2024-01-01T00:00:00Z", 37) // { seconds: 1704067237n, nanoseconds: 0 }
output 

iot/convert/utcToPtp.ts

© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.