Set the local week to the given date.
Set the local week to the given date, saving the weekday number.
The exact calculation depends on the values of
options.weekStartsOn (which is the index of the first day of the week)
and options.firstWeekContainsDate (which is the day of January, which is always in
the first week of the week-numbering year)
Week numbering: https://en.wikipedia.org/wiki/Week#Week_numbering
// CommonJS
var setWeek = require('date-fns/setWeek')
// ES 2015 import setWeek from 'date-fns/setWeek'
// ESM
import { setWeek } from 'date-fns'
setWeek(date, week, [options])
| Name | Description |
|---|---|
date |
the date to be changed |
week |
the week of the new date |
options |
an object with options. |
options.locale |
the locale object. See [Locale]{@link https://date-fns.org/docs/Locale} |
options.weekStartsOn |
the index of the first day of the week (0 - Sunday) |
options.firstWeekContainsDate |
the day of January, which is always in the first week of the year |
| Description |
|---|
|
the new date with the local week set |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
RangeError |
|
RangeError |
|
// Set the 1st week to 2 January 2005 with default options: const result = setWeek(new Date(2005, 0, 2), 1) //=> Sun Dec 26 2004 00:00:00
// Set the 1st week to 2 January 2005,
// if Monday is the first day of the week,
// and the first week of the year always contains 4 January:
const result = setWeek(new Date(2005, 0, 2), 1, {
weekStartsOn: 1,
firstWeekContainsDate: 4
})
//=> Sun Jan 4 2004 00:00:00
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/setWeek