Skip to content

lochungtin/calendarJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CalendarJS

Simple calendar grid generator for NodeJS

Install

With NPM

npm install --save @enigmaoffline/calendarjs

Usage

const Calendar = require('@enigmaoffline/calendarjs');

let cl = new Calendar(2020, 12);

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

console.log(cl.isLeapYear());   // => true

cl.nextMonth();

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

Static Usage

const Calendar = require('@enigmaoffline/calendarjs');

console.log(Calendar.getDateNum(2020, 2));  // => 29
console.log(Calendar.getDateNum(2020, 3));  // => 31

console.log(Calendar.getNextMonth(2021, 12));   // => { month: 1, year: 2022 }

LICENSE - MIT - Lo Chung Tin