nextWeekday
Signature
Section titled “Signature”nextWeekday(value: string, dayOfWeek: number, options?: { inclusive?: boolean; }): stringReturn a PlainDate ISO string for the next occurrence of dayOfWeek on or after value.
-
dayOfWeekuses Temporal’s ISO numbering: 1 (Monday) through 7 (Sunday), consistent withgetDayOfWeek/parseDayOfWeekFromDate. -
Returns "" on invalid input. Replaces date-fns’s sixteen
next*functions with one parameterized call:date-fns gmt nextMondaynextWeekday(value, 1)nextTuesdaynextWeekday(value, 2)nextWednesdaynextWeekday(value, 3)nextThursdaynextWeekday(value, 4)nextFridaynextWeekday(value, 5)nextSaturdaynextWeekday(value, 6)nextSundaynextWeekday(value, 7)nextDay(v, n)nextWeekday(value, n)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string |
dayOfWeek | number | target ISO day of week (1-7, Monday-Sunday) |
Options
Section titled “Options”options
Whether value itself can be the result
| Option | Type | Default | Description |
|---|---|---|---|
inclusive? | boolean | false | Whether value counts when it already falls on dayOfWeek. true returns value unchanged; false advances a full week. |
Returns
Section titled “Returns”ISO PlainDate string for the next occurrence of dayOfWeek, or "" on invalid input
Examples
Section titled “Examples”import { nextWeekday } from "@northguild/gmt/plain/calculate";
nextWeekday("2024-03-15", 5) // "2024-03-22" (2024-03-15 is already a Friday, so it advances a full week)