RunKit + npm: dayjs

node v14.20.1
endpointsharetweet
const dayjs = require("dayjs") const weekOfYear = require('dayjs/plugin/weekOfYear') const locale = require('dayjs/locale/fr') dayjs.locale('fr') dayjs.extend(weekOfYear) const selectedDay = dayjs().day() const selectedWeek = dayjs().week() // If today is 2023-01-02 then it should be 2022-01-03 console.log(dayjs.locale(), dayjs().subtract(1, 'year').week(selectedWeek).day(selectedDay).format('YYYY-MM-DD')) const selectedDay2 = dayjs().set('date', 31).day() const selectedWeek2 = dayjs().set('date', 31).week() // Working as intended after the 2023-01-31 console.log(dayjs().set('date', 31).subtract(1, 'year').week(selectedWeek2).day(selectedDay2).format('YYYY-MM-DD')) // Possible fix const updateLocale = require('dayjs/plugin/updateLocale') dayjs.extend(updateLocale) dayjs.updateLocale('fr', { yearStart: 0 }) // If today is 2023-01-02 then it should be 2022-01-03 console.log(dayjs().subtract(1, 'year').week(selectedWeek).day(selectedDay).format('YYYY-MM-DD'))
Created from: https://npm.runkit.com/dayjs
Loading…