Loading lesson path
Temporal is a powerful API, but it can be confusing at first.
Formula
Use compare() instead of < and >Here are some common mistakes and how to avoid them. Missing UTC (Z) for Instant An Instant must always include UTC.
Formula
Wrong const instant = Temporal.Instant.from("2026 - 05 - 17T14:30:00");
Correct const instant = Temporal.Instant.from("2026 - 05 - 17T14:30:00Z");PlainDateTime does not support time zones.
Formula
Wrong const date = Temporal.PlainDateTime.from("2026 - 05 - 17T14:30:00Z");
Correct const date = Temporal.ZonedDateTime.from("2026 - 05 - 17T14:30:00");Temporals can go wrong when comparing different types.
Wrong const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.Instant.from("2026-05-17T14:30Z");
Temporal.PlainDate.compare(d1, d2);
Correct const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.PlainDateTime.from("2026-05-17T14:30");
Temporal.PlainDate.compare(d1, d2);Temporals can go wrong when comparing different types.
Wrong const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.Instant.from("2026-05-17T14:30Z");
d1.equals(d2);
Correct const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.PlainDateTime.from("2026-05-17T14:30");
d1.equals(d2.toPlainDate());Formula
Using ==, < or > for ComparisonTemporal objects cannot be compared with ==, ===, < or >.
Wrong const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.PlainDate.from("2026-05-17");
d1 === d2; // False d1 == d2; // False d1 < d2; // TypeError d1 > d2; // TypeError
Correct const d1 = Temporal.PlainDate.from("2026-05-17");
const d2 = Temporal.PlainDate.from("2026-05-17");
Temporal.PlainDate.compare(d1, d2);Temporal objects are immutable.
Wrong const date = Temporal.PlainDate.from("2026-05-17");
date.add({ months: 1 });
Correct const date = Temporal.PlainDate.from("2026-05-17");
const next = d.add({ months: 1 });Temporal objects do not convert to numbers.
const date = Temporal.PlainDate.from("2026-05-17");
try {
text = date.valueOf();
} catch (err) {
text = err.name;
}Instant is always UTC (not local time).
Temporal.Now.instant(); // not local timeTemporal.Now.zonedDateTimeISO() to get local time:
Temporal.Now.zonedDateTimeISO();PlainDate has no time.
Formula
Temporal.PlainDate.from("2026 - 05 - 17T14:30");Formula
Temporal.PlainDateTime.from("2026 - 05 - 17T14:30");ZonedDateTime requires a time zone.
Formula
Temporal.ZonedDateTime.from("2026 - 05 - 17T14:30:00");Formula
Temporal.ZonedDateTime.from("2026 - 05 - 17T14:30:00 + 02:00[Europe/Oslo]");Each Temporal type has a specific purpose.