Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calendario

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calendario - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

19

docs/PT-BR.md
# calendario
> Verifique dias de trabalho, feriados, finais de semanda ou crie seus próprios eventos.
> Verifique dias de trabalho, feriados, finais de semana ou crie seus próprios eventos.

@@ -18,3 +18,3 @@ [![NPM Version](https://img.shields.io/npm/v/express.svg?style=flat)](https://www.npmjs.org/package/calendario)

Atualmente as fontes suportam apenas eventos nacionais (com excessão do Brasil e Estados Unidos). Na próxima release será adicionado mais fontes nacionais e regionais.
Atualmente as fontes suportam apenas eventos nacionais (com exceção do Brasil e Estados Unidos). Na próxima release será adicionado mais fontes nacionais e regionais.

@@ -35,3 +35,3 @@ **Disponível para:**

Definindo a fonte para um estado específico
Definindo a fonte para um estado específico:

@@ -100,3 +100,3 @@ ```javascript

Retorna todos os eventos específicados de um começo até um fim:
Retorna todos os eventos especificados de um começo até um fim:

@@ -164,3 +164,3 @@ ```javascript

Remove todos as fontes definidas:
Remove todas fontes definidas:

@@ -173,2 +173,11 @@ ```javascript

#### ignoreWeekends
Por padrão, o calendario não considera finais de semana como dias de trabalho. Porém você consegue mudar essa configuração usando:
```javascript
var calendario = require('calendario');
calendario.ignoreWeekends();
```
## Fonte de Dados

@@ -175,0 +184,0 @@

module.exports = require('./src/calendario.js');
var calendario = require('./src/calendario.js');
{
"name": "calendario",
"version": "1.1.3",
"version": "1.1.4",
"description": "Check if a day is a workday or holiday",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -173,2 +173,11 @@ # calendario

#### ignoreWeekends
By default the calendario don't consider weekends as workdays. However you can change this using:
```javascript
var calendario = require('calendario');
calendario.ignoreWeekends();
```
## Data Source

@@ -175,0 +184,0 @@

@@ -7,5 +7,10 @@ 'use strict';

function sameDay(date1, date2){
return date1.toDateString() === date2.toDateString();
}
function Calendario() {
this.events = []; // [{date: 1, source: }, {date: 1, source: }]
this.events = [];
this.sources = [];
this.ignoreWeekend = false;
}

@@ -90,2 +95,9 @@

Calendario.prototype.ignoreWeekends = function(bool) {
if (bool === false)
return this.ignoreWeekend = false;
this.ignoreWeekend = true;
}
Calendario.prototype.eventList = function() {

@@ -101,12 +113,2 @@ var events = this.sources.map(function(a,b) { return a['events'] }),

Calendario.prototype.sameDay = function(dateEarlier, dateLater) {
var earlier = dateEarlier.getDate() + '-' + dateEarlier.getMonth() + '-' + dateEarlier.getFullYear(),
later = dateLater.getDate() + '-' + dateLater.getMonth() + '-' + dateLater.getFullYear();
if (earlier === later)
return true;
return false;
}
Calendario.prototype.dayDiff = function(dateEarlier, dateLater) {

@@ -118,8 +120,7 @@ var dayTime = 1000 * 60 * 60 * 24;

Calendario.prototype.aboutDay = function(date) {
var self = this,
events = this.eventList(),
day = [];
var events = this.eventList(),
day = [];
events.forEach(function(ev) {
if (self.sameDay(date, ev.date))
if (sameDay(date, ev.date))
day.push(ev);

@@ -132,8 +133,12 @@ })

Calendario.prototype.isWorkday = function(date) {
var self = this,
events = this.eventList(),
var events = this.eventList(),
workday = true;
if (!this.ignoreWeekend) {
if (date.getDay() === 0 || date.getDay() === 6)
return false;
}
events.forEach(function(ev) {
if (self.sameDay(date, ev.date))
if (sameDay(date, ev.date))
workday = ev.workday

@@ -140,0 +145,0 @@ })

@@ -5,2 +5,81 @@ var assert = require('assert'),

describe('isWorkday()', function() {
context("Weekends", function() {
context('- when exists a workday in a weekend (saturday, sunday)', function() {
it('should get false', function(done) {
calendario.clear();
var arrayOfEvents = [
{
date: new Date('2015-06-27'),
workday: true,
summary: "Mozilla Summit on Saturday"
},
{
date: new Date('2015-06-28'),
workday: true,
summary: "Mozilla another on Sunday"
}
];
calendario.use('MozillaCalendar', arrayOfEvents);
var workdayOnSaturday = calendario.isWorkday(new Date('2015-06-27 01:00'));
var workdayOnSunday = calendario.isWorkday(new Date('2015-06-28 01:00'));
assert.equal(workdayOnSaturday, false);
assert.equal(workdayOnSunday, false);
done();
});
})
context('- ignore if a workday is weekend (saturday, sunday)', function() {
it('should get true', function(done) {
calendario.clear();
var arrayOfEvents = [
{
date: new Date('2015-06-27'),
workday: true,
summary: "Mozilla Summit on Saturday"
},
{
date: new Date('2015-06-28'),
workday: true,
summary: "Mozilla another on Sunday"
}
];
calendario.use('MozillaCalendar', arrayOfEvents);
calendario.ignoreWeekends();
var workdayOnSaturday = calendario.isWorkday(new Date('2015-06-27 01:00'));
var workdayOnSunday = calendario.isWorkday(new Date('2015-06-28 01:00'));
assert.equal(workdayOnSaturday, true);
assert.equal(workdayOnSunday, true);
done();
});
})
context('- set if a workday is a weekend, must don\'t be a workday (saturday, sunday)', function() {
it('should get false', function(done) {
calendario.clear();
var arrayOfEvents = [
{
date: new Date('2015-06-27'),
workday: true,
summary: "Mozilla Summit on Saturday"
},
{
date: new Date('2015-06-28'),
workday: true,
summary: "Mozilla another on Sunday"
}
];
calendario.use('MozillaCalendar', arrayOfEvents);
calendario.ignoreWeekends(false);
var workdayOnSaturday = calendario.isWorkday(new Date('2015-06-27 01:00'));
var workdayOnSunday = calendario.isWorkday(new Date('2015-06-28 01:00'));
assert.equal(workdayOnSaturday, false);
assert.equal(workdayOnSunday, false);
done();
});
})
})
context("Valid Input", function() {

@@ -7,0 +86,0 @@ context("US • United States National", function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc