Getting the Current Time
getNow, getToday, and their zoned/UTC/Unix siblings are the entry point for
every other operation. These mistakes cover the ways reaching for them goes wrong.
Mistakes
Section titled “Mistakes”Using Date.now() instead of Temporal
Date.now() returns epoch milliseconds. GMT functions return ISO strings. They are not interchangeable — 1000× errors are the common result.
Wrong
const ts = Date.now(); // 1710504645000 — milliseconds, but easy to mistake for secondsRight
import { getNow } from "@northguild/gmt";
getNow(); // "2024-03-15T14:30:45" — ISO 8601 string, no unit confusionUsing new Date() for current time
new Date() produces a mutable Date object. GMT returns immutable strings. Mixing the two families forces constant round-tripping and hides timezone bugs.
Wrong
const now = new Date(); // mutable Date object — implicit system timezoneRight
import { getNow } from "@northguild/gmt";
getNow(); // "2024-03-15T14:30:45" — immutable stringNot handling empty string on error
GMT returns an empty string for invalid input rather than throwing. Treating a falsy return as 'not yet loaded' or skipping the branch silently is a bug.
Wrong
const now = getNow?.(); // if the call returns "", your check may treat it as undefinedRight
import { getNow } from "@northguild/gmt";
const now = getNow(); // "" on failure — check explicitly:
if (now === "") {
// handle failure
}Looking for value-taking get* functions here
getNow and getToday take no arguments. Passing a timezone or format string throws — the zoned and UTC variants live in their own namespaces.
Wrong
getNow("America/New_York"); // ERROR: getNow takes no argumentsRight
import { getZonedNow } from "@northguild/gmt/zoned";
getZonedNow("America/New_York"); // "2024-03-15T10:30:45" — zoned variantBucketing by week number without its week-year
A week number (1-53) is not unique without the week-year. Week 1 of 2024 and week 1 of 2025 are different weeks, but the number alone does not tell you which.
Wrong
const week = parseWeekFromDate("2024-01-01"); // 1 — but which year's week 1?Right
import { parseWeekFromDate, parseYearFromDate } from "@northguild/gmt";
const year = parseYearFromDate("2024-01-01"); // 2024
const week = parseWeekFromDate("2024-01-01"); // 1
// week 1 of 2024 is unambiguous