monthly-calendar-date-helper

0.1.0 • Public • Published

monthly-calendar-date-helper

A simple utility that given a month and year returns an array of dates to be used in a monthly calendar. Shows previous and next months days to pad out the calendar so the calendar always starts on Sunday and lasts for 6 weeks. Option to split by week.

Installation

npm i -S monthly-calendar-date-helper

Usage

import calendarDates from 'monthly-calendar-date-helper'
 
// Returns and array of date objects, always equalling 42 days
const dates = calendarDates(12, 2016)
 
/*
[ 2016-11-27T08:00:00.000Z,
  2016-11-28T08:00:00.000Z,
  2016-11-29T08:00:00.000Z,
  2016-11-30T08:00:00.000Z,
  2016-12-01T08:00:00.000Z,
  2016-12-02T08:00:00.000Z,
  2016-12-03T08:00:00.000Z,
  2016-12-04T08:00:00.000Z,
  2016-12-05T08:00:00.000Z,
  2016-12-06T08:00:00.000Z,
  2016-12-07T08:00:00.000Z,
  2016-12-08T08:00:00.000Z,
  2016-12-09T08:00:00.000Z,
  2016-12-10T08:00:00.000Z,
  2016-12-11T08:00:00.000Z,
  2016-12-12T08:00:00.000Z,
  2016-12-13T08:00:00.000Z,
  2016-12-14T08:00:00.000Z,
  2016-12-15T08:00:00.000Z,
  2016-12-16T08:00:00.000Z,
  2016-12-17T08:00:00.000Z,
  2016-12-18T08:00:00.000Z,
  2016-12-19T08:00:00.000Z,
  2016-12-20T08:00:00.000Z,
  2016-12-21T08:00:00.000Z,
  2016-12-22T08:00:00.000Z,
  2016-12-23T08:00:00.000Z,
  2016-12-24T08:00:00.000Z,
  2016-12-25T08:00:00.000Z,
  2016-12-26T08:00:00.000Z,
  2016-12-27T08:00:00.000Z,
  2016-12-28T08:00:00.000Z,
  2016-12-29T08:00:00.000Z,
  2016-12-30T08:00:00.000Z,
  2016-12-31T08:00:00.000Z,
  2017-01-01T08:00:00.000Z,
  2017-01-02T08:00:00.000Z,
  2017-01-03T08:00:00.000Z,
  2017-01-04T08:00:00.000Z,
  2017-01-05T08:00:00.000Z,
  2017-01-06T08:00:00.000Z,
  2017-01-07T08:00:00.000Z ]
  */
 
// Split into an array of weeks
calendarDates(7, 2015, { split: true })
 
/*
[ [ 2016-03-27T07:00:00.000Z,
    2016-03-28T07:00:00.000Z,
    2016-03-29T07:00:00.000Z,
    2016-03-30T07:00:00.000Z,
    2016-03-31T07:00:00.000Z,
    2016-04-01T07:00:00.000Z,
    2016-04-02T07:00:00.000Z ],
  [ 2016-04-03T07:00:00.000Z,
    2016-04-04T07:00:00.000Z,
    2016-04-05T07:00:00.000Z,
    2016-04-06T07:00:00.000Z,
    2016-04-07T07:00:00.000Z,
    2016-04-08T07:00:00.000Z,
    2016-04-09T07:00:00.000Z ],
  [ 2016-04-10T07:00:00.000Z,
    2016-04-11T07:00:00.000Z,
    2016-04-12T07:00:00.000Z,
    2016-04-13T07:00:00.000Z,
    2016-04-14T07:00:00.000Z,
    2016-04-15T07:00:00.000Z,
    2016-04-16T07:00:00.000Z ],
  [ 2016-04-17T07:00:00.000Z,
    2016-04-18T07:00:00.000Z,
    2016-04-19T07:00:00.000Z,
    2016-04-20T07:00:00.000Z,
    2016-04-21T07:00:00.000Z,
    2016-04-22T07:00:00.000Z,
    2016-04-23T07:00:00.000Z ],
  [ 2016-04-24T07:00:00.000Z,
    2016-04-25T07:00:00.000Z,
    2016-04-26T07:00:00.000Z,
    2016-04-27T07:00:00.000Z,
    2016-04-28T07:00:00.000Z,
    2016-04-29T07:00:00.000Z,
    2016-04-30T07:00:00.000Z ],
  [ 2016-05-01T07:00:00.000Z,
    2016-05-02T07:00:00.000Z,
    2016-05-03T07:00:00.000Z,
    2016-05-04T07:00:00.000Z,
    2016-05-05T07:00:00.000Z,
    2016-05-06T07:00:00.000Z,
    2016-05-07T07:00:00.000Z ] ]
*/

API

calendarDates(month, year[, options])

  • month - The month as a number
  • year - The year as a number
  • options (optional)
    • split (default: false) - whether or not to split result into an array of weeks instead of just all the days in one list.

Changes

See changelog.md.

License

MIT by Dana Woodman 2016. See license file.

/monthly-calendar-date-helper/

    Package Sidebar

    Install

    npm i monthly-calendar-date-helper

    Weekly Downloads

    1

    Version

    0.1.0

    License

    ISC

    Last publish

    Collaborators

    • danawoodman