Get and set
Each unit is a method: called without an argument it reads the unit, called with one it returns a copy with that unit set.
const day = yuga("2024-05-15 10:20");
day.year(); // 2024day.month(); // 4, months count from 0day.date(); // 15, the day of the monthday.day(); // 3, the day of the week (0 is Sunday)day.hour(); // 10day.minute(); // 20day.second(); // 0day.millisecond(); // 0day.quarter(); // 2day.week(); // 20, the ISO weekget and set take the unit by name, in any of Day.js’s spellings ("month", "months", "M"):
yuga("2024-05-15").get("quarter"); // 2yuga("2024-05-15").set("month", 0); // 2024-01-15Setting overflows the way Day.js does
Section titled “Setting overflows the way Day.js does”Setting a month keeps the day where it can and clamps it at the end of a shorter month:
yuga("2024-01-31").month(1).date(); // 29Other units roll over into the next one, so date(32) in May is the 1st of June, and hour(-1) is 23:00 the day before.
Setting a unit is an operation on the wall clock in the instance’s time zone. In the hour repeated when clocks go back, yuga keeps the offset the instance had when it’s still valid, the same as Temporal’s with.
More units
Section titled “More units”daysInMonth()is the number of days in the instance’s month.- The
weeksextension adds the locale’s week (weekday,weekYear) and the ISO week year. day-of-year,is-leap-yearandplural-get-set(years(),months()…) add what their names say.