Giter Site home page Giter Site logo

danawoodman / monthly-calendar-date-helper Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 7 KB

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.

Home Page: https://www.npmjs.com/package/monthly-calendar-date-helper

License: MIT License

JavaScript 100.00%
javascript date calendar utility util month monthly js node

monthly-calendar-date-helper's Introduction

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's People

Contributors

danawoodman avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.