Skip to content

Working with Temporal

yuga is built on Temporal. It takes Temporal values in and gives them back, so you can move between the two at any point.

yuga(Temporal.Now.zonedDateTimeISO("Asia/Tokyo")); // Keeps its time zone.
yuga(Temporal.Instant.from("2024-05-15T10:20:00Z"));

Temporal.PlainDate and Temporal.PlainDateTime need the plain-date-support extension, since they have no time zone of their own: they’re read as a wall clock in the instance’s time zone.

const day = yuga.tz("2024-05-15 10:20", "Asia/Tokyo");
day.toTemporal(); // Temporal.ZonedDateTime
day.toInstant().toString(); // "2024-05-15T01:20:00Z"
day.toPlainDate().toString(); // "2024-05-15"
day.toTemporal().toPlainTime().toString(); // "10:20:00"

Use Temporal for what Day.js’s API doesn’t have, such as other calendars, and come back with yuga(zonedDateTime).

An instance holds milliseconds since the epoch, a time zone and a locale. Its Temporal.ZonedDateTime is only built the first time something needs it, so most code never builds one. See Performance and size.