UNPKG

@sanity/scheduled-publishing

Version:

> [!IMPORTANT] > As of [v3.39.0](https://www.sanity.io/changelog/e6013ee5-8214-4e03-9593-f7b19124b8a3) of Sanity Studio, this plugin has been deprecated and the Scheduled Publishing functionality has been moved into the core studio package. > Read more an

31 lines (26 loc) 769 B
import {addDays, eachWeekOfInterval, getWeek, lastDayOfMonth, startOfMonth} from 'date-fns' import {TAIL_WEEKDAYS} from './constants' export const getWeekStartsOfMonth = (date: Date): Date[] => { const firstDay = startOfMonth(date) return eachWeekOfInterval({ start: firstDay, end: lastDayOfMonth(firstDay), }) } export const getWeekDaysFromWeekStarts = (weekStarts: Date[]): Date[][] => { return weekStarts.map((weekStart) => [ weekStart, ...TAIL_WEEKDAYS.map((d) => addDays(weekStart, d)), ]) } type Week = { number: number days: Date[] } export const getWeeksOfMonth = (date: Date): Week[] => getWeekDaysFromWeekStarts(getWeekStartsOfMonth(date)).map( (days): Week => ({ number: getWeek(days[0]), days, }) )