Calendar Helpers

Various helpers related to calendar specific functionality.

Source code is hosted on GitHub

yarn add @corets/calendar-helpers

createCalendarMonthView()

Generate a 6 x 7 multidimensional array containing dates based on the given date:

import { createCalendarMonthView } from "@corets/calendar-helpers"

const today = new Date("2020-04-26")
const weeks = createCalendarMonthView(today)

This array can be used to render a custom calendar widget or a month view:

[
  // 2020-03-30, 2020-03-31, 2020-04-01, 2020-04-02, 2020-04-03, 2020-04-04, 2020-04-05
  [Date, Date, Date, Date, Date, Date, Date],
  // 2020-04-06, 2020-04-07, 2020-04-08, 2020-04-09, 2020-04-10, 2020-04-11, 2020-04-12
  [Date, Date, Date, Date, Date, Date, Date],
  // 2020-04-13, 2020-04-14, 2020-04-15, 2020-04-16, 2020-04-17, 2020-04-18, 2020-04-19
  [Date, Date, Date, Date, Date, Date, Date],
  // 2020-04-20, 2020-04-21, 2020-04-22, 2020-04-23, 2020-04-24, 2020-04-25, 2020-04-26
  [Date, Date, Date, Date, Date, Date, Date],
  // 2020-04-27, 2020-04-28, 2020-04-29, 2020-04-30, 2020-05-01, 2020-05-02, 2020-05-03
  [Date, Date, Date, Date, Date, Date, Date],
  // 2020-05-04, 2020-05-05, 2020-05-06, 2020-05-07, 2020-05-08, 2020-05-09, 2020-05-10
  [Date, Date, Date, Date, Date, Date, Date],
]

Last updated