A TS Date Read as a Time
A TS Date Read as a Time
An older feed sends an HL7 TS with its degree of precision: 199904011200^L. The receiver splits off the first component and reads a time.
The naive approach
// The naive approach: keep the first component, drop the degree of precision
const value = "199904011200^L";
const dtm = value.split("^")[0];
dtm.slice(0, 4) + "-" + dtm.slice(4, 6) + "-" + dtm.slice(6, 8) + "T" + dtm.slice(8, 10) + ":" + dtm.slice(10, 12) + ":00";
// "1999-04-01T12:00:00" — the sender said April 1999Watch it break
The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.
Why
In a TS the letter after the caret is the degree of precision, and L is the month. It overrides the digits and may only lower them. The value names April 1999, not noon on the first. parseHL7 cuts the value to the precision and returns a partial value with no instant. A degree finer than the digits sent is refused, because it would claim a precision the sender did not have.
The gmt approach
import { parseHL7 } from "@northguild/gmt/healthcare/parse";
parseHL7("199904011200^L");
// { kind: "partial", local: "1999-04", offset: "", precision: "month" }
parseHL7("20240615103000^D");
// { kind: "partial", local: "2024-06-15", offset: "", precision: "day" }
parseHL7("20240615^S");
// null — a second is finer than the day sentSame widget, working
Type 199904011200^L into the widget and it returns a month. Delete ^L and the same digits read
as a time. The full rules are in
Healthcare: Clinical Timestamps.
© 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.