Giter VIP home page Giter VIP logo

calendario's Introduction

calendario

Check if a day is a workday or holiday.

NPM Version Build Status Coverage Status

Available too: brazilian portuguese.

Install

Before anything, you need to have node and npm installed.

$ npm install calendario

Usage

Available for:

You can set the calendar using use()

var calendario = require('calendario');
calendario.use('BR');

Setting the calendar for a specific state

var calendario = require('calendario');
calendario.use('US-NY');

You can create your owns calendars, passing a array of objects like these:

var calendario = require('calendario');

calendario.use('MozillaCalendar', [
	{date: new Date('2020-11-25'), workday: true, summary: "Mozilla Summit"},
	{date: new Date('2021-1-20'), workday: true, summary: "Mozilla another event"}
]);

calendario.use('GoogleCalendar', function(set) {
	set([
		{date: new Date('2017-6-3'), workday: true, summary: "Google IO"},
		{date: new Date('2018-10-5'), workday: true, summary: "Google another event"},
	]);
});

You can create your own calendar, passing a ics file

var calendario = require('calendario');
calendario.use('BR', {file: 'pt-br.ics', parser: 'ics'});

Methods

isWorkday

Verify if the day in question is a working day, based on defined calendar sources:

var calendario = require('calendario');
calendario.use('BR');

calendario.isWorkday(new Date('2015-05-01')); // false
calendario.isWorkday(new Date('2015-05-02')); // true

aboutDay

Get all events about specified day:

var calendario = require('calendario');
calendario.use('US');

calendario.aboutDay(new Date('2015-12-25'))
/*
[ { date: Fri Dec 25 2015 00:00:00 GMT-0200 (BRST),
    summary: 'Christmas Day',
    workday: false } ]
*/

range

Get all events from a specified begin to a specified end:

var calendario = require('calendario');
calendario.use('US');

var range = calendario.range()
		.begin(new Date('2015-12-20'))
		.end(new Date('2016-01-05'))
		.toArray();

/*
[ { date: Thu Dec 24 2015 00:00:00 GMT-0200 (BRST),
    summary: 'Christmas Eve (from 2pm)',
    workday: false },
  { date: Fri Dec 25 2015 00:00:00 GMT-0200 (BRST),
    summary: 'Christmas Day',
    workday: false },
  { date: Thu Dec 31 2015 00:00:00 GMT-0200 (BRST),
    summary: 'New Year\'s Eve (from 2pm)',
    workday: false },
  { date: Fri Jan 01 2016 00:00:00 GMT-0200 (BRST),
    summary: 'New Year\'s Day',
    workday: false } ]
*/

sourceList

Return all defined calendars as source:

var calendario = require('calendario');
calendario.use('US');
calendario.use('BR');

calendario.sourceList(); // ['US', 'BR']

eventList

Return the events from all sources:

var calendario = require('calendario');
calendario.use('MozillaCalendar', [
	{date: new Date('2020-11-25'), workday: true, summary: "Mozilla Summit"},
	{date: new Date('2021-1-20'), workday: true, summary: "Mozilla another event"}
]);

calendario.eventList();
/*
[ { workday: true,
    summary: 'Mozilla Summit',
    date: Tue Nov 24 2020 22:00:00 GMT-0200 (BRST) },
  { workday: true,
    summary: 'Mozilla another event',
    date: Wed Jan 20 2021 00:00:00 GMT-0200 (BRST) } ]
*/

clear

Clear and remove all previously defined sources:

var calendario = require('calendario');
calendario.use('BR'); // Sources: ['BR']
calendario.clear(); // Sources: []

ignoreWeekends

By default the calendario don't consider weekends as workdays. However you can change this using:

var calendario = require('calendario');
calendario.ignoreWeekends();

Data Source

Brazil

United States of America

History

See Changelog for more details.

Contributing

Don't be shy, send a Pull Request! Here is how:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

About

License: MIT ® Raphael Amorim

calendario's People

Contributors

iamgbayer avatar ianramosc avatar israelst avatar raphamorim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

calendario's Issues

Fix example in README for isWorkday

It seems that the example on README for the isWorkDay method is wrong: the same line of code returns true and false:

var calendario = require('calendario');
calendario.use('BR');

calendario.isWorkday(new Date('2015-05-01')); // false
calendario.isWorkday(new Date('2015-05-01')); // true

Shouldn't dates be different in each line?

Add support to cities holydays

Here in Brazil cities also have it holydays...I know, there's too much cities in the world (ever in Brazil)... but...

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.