previousWeekday
Signature
Section titled “Signature”previousWeekday(value: string, dayOfWeek: number, options?: { inclusive?: boolean; }): stringReturn a PlainDate ISO string for the previous occurrence of dayOfWeek on or before value.
-
dayOfWeekuses Temporal’s ISO numbering: 1 (Monday) through 7 (Sunday), consistent withgetDayOfWeek/parseDayOfWeekFromDate. -
Returns "" on invalid input. Replaces date-fns’s sixteen
previous*functions with one parameterized call:date-fns gmt previousMondaypreviousWeekday(value, 1)previousTuesdaypreviousWeekday(value, 2)previousWednesdaypreviousWeekday(value, 3)previousThursdaypreviousWeekday(value, 4)previousFridaypreviousWeekday(value, 5)previousSaturdaypreviousWeekday(value, 6)previousSundaypreviousWeekday(value, 7)previousDay(v, n)previousWeekday(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 goes back a full week. |
Returns
Section titled “Returns”ISO PlainDate string for the previous occurrence of dayOfWeek, or "" on invalid input
Examples
Section titled “Examples”import { previousWeekday } from "@northguild/gmt/plain/calculate";
previousWeekday("2024-03-15", 5) // "2024-03-08" (2024-03-15 is already a Friday, so it goes back a full week)