Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.
/ mnth Public archive

📆 Calendar month as 2d array of Dates

License

Notifications You must be signed in to change notification settings

deepsweet/mnth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mnth

⚠️ Project has been transferred to NexTools metarepo

npm tests coverage

Framework-agnostic base block to build calendars, datepickers, etc by rendering 2d array of Dates.

Requirements

Node

Browser

Install

$ yarn add date-fns@next mnth

Usage

mnth(date, options)
  • date – Date object
  • options
    • firstDay – first day of the week, from 0 to 6, 1 by default
import { format, parse } from 'date-fns/esm'
import mnth from 'mnth'

const date = parse('2018-04-01', 'yyyy-MM-dd', new Date())
const month = mnth(date).map((week) =>
  week.map((day) => format(day, 'yyyy-MM-dd'))
)

console.log(month)
/*
[
  [ '2018-03-26', '2018-03-27', '2018-03-28', '2018-03-29', '2018-03-30', '2018-03-31', '2018-04-01' ],
  [ '2018-04-02', '2018-04-03', '2018-04-04', '2018-04-05', '2018-04-06', '2018-04-07', '2018-04-08' ],
  [ '2018-04-09', '2018-04-10', '2018-04-11', '2018-04-12', '2018-04-13', '2018-04-14', '2018-04-15' ],
  [ '2018-04-16', '2018-04-17', '2018-04-18', '2018-04-19', '2018-04-20', '2018-04-21', '2018-04-22' ],
  [ '2018-04-23', '2018-04-24', '2018-04-25', '2018-04-26', '2018-04-27', '2018-04-28', '2018-04-29' ],
  [ '2018-04-30', '2018-05-01', '2018-05-02', '2018-05-03', '2018-05-04', '2018-05-05', '2018-05-06' ]
]
*/