Add, subtract, start and end
yuga("2024-01-31").add(1, "month"); // 2024-02-29yuga("2024-03-31").subtract(1, "month"); // 2024-02-29yuga().add(2, "hours").add(30, "minutes");yuga().subtract(1, "week");Days, weeks, months, quarters and years move the wall clock, so add(1, "day") across a change of clocks lands on the same time the next day. Hours, minutes, seconds and milliseconds move the instant, so add(24, "hours") on the same day can land an hour off.
A month added to the 31st ends on the last day of a shorter month, the same as Day.js.
Start and end of a unit
Section titled “Start and end of a unit”yuga("2024-05-15 10:20").startOf("month"); // 2024-05-01 00:00yuga("2024-05-15").endOf("day").format("HH:mm:ss.SSS"); // "23:59:59.999"yuga().startOf("week"); // Sunday in en, Monday in en-gbyuga().startOf("isoWeek"); // Monday, in every localeweek starts on the locale’s first day of the week, read from Intl. isoWeek always starts on Monday.
Durations
Section titled “Durations”With the duration plugin, add and subtract also take a duration. See Durations.