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

moment-business-time

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-business-time - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

8

lib/business-hours.js

@@ -17,4 +17,4 @@ var moment = require('moment');

moment.locale(locale, {
workinghours: function () { return localeData.HOURS; },
holidays: function () { return localeData.HOLIDAYS; }
workinghours: localeData.HOURS,
holidays: localeData.HOLIDAYS
});

@@ -24,3 +24,3 @@

d = d.clone();
var hours = moment.localeData().workinghours();
var hours = moment.localeData()._workinghours;
if (!d.isWorkingDay()) {

@@ -149,3 +149,3 @@ return null;

moment.fn.isBusinessDay = function isBusinessDay() {
var hours = moment.localeData().workinghours();
var hours = moment.localeData()._workinghours;
return !!hours[this.day()] && !this.isHoliday();

@@ -152,0 +152,0 @@ };

module.exports = {
HOURS: {
1: ['09:00:00', '17:00:00'],
2: ['09:00:00', '17:00:00'],
3: ['09:00:00', '17:00:00'],
4: ['09:00:00', '17:00:00'],
5: ['09:00:00', '17:00:00'],
6: null,
7: null
0: null,
1: ['09:00:00', '17:00:00'],
2: ['09:00:00', '17:00:00'],
3: ['09:00:00', '17:00:00'],
4: ['09:00:00', '17:00:00'],
5: ['09:00:00', '17:00:00'],
6: null
},
HOLIDAYS: []
};
{
"name": "moment-business-time",
"version": "0.1.0",
"version": "0.1.1",
"description": "Query and manipulate moment objects within the context of business/working hours",

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

@@ -124,2 +124,25 @@ # moment-business-time

## Configuration
The working hours used for a locale can be modified using moment's `locale` method.
Example:
```javascript
// set opening time to 09:30 and close early on Wednesdays
moment.locale('en', {
workinghours: {
0: null,
1: ['09:30:00', '17:00:00'],
2: ['09:30:00', '17:00:00'],
3: ['09:30:00', '13:00:00'],
4: ['09:30:00', '17:00:00'],
5: ['09:30:00', '17:00:00'],
6: null
}
});
moment('Wed Feb 25 2015 15:00:00 GMT+0000').isWorkingTime() // false
moment('Mon Feb 23 2015 09:00:00 GMT+0000').isWorkingTime() // false
```
## Running tests

@@ -126,0 +149,0 @@

@@ -291,2 +291,74 @@ var moment = require('../lib/business-hours');

describe('modified locales', function () {
beforeEach(function () {
moment.locale('en');
});
afterEach(function () {
localeData = require('../locale/default');
moment.locale(moment.locale(), {
workinghours: localeData.HOURS
});
});
it('handles inconsistent opening hours', function () {
moment.locale('en', {
workinghours: {
0: null,
1: ['12:00:00', '17:00:00'],
2: ['09:30:00', '17:00:00'],
3: ['10:00:00', '17:00:00'],
4: ['09:00:00', '17:00:00'],
5: ['09:30:00', '17:00:00'],
6: null
}
});
var mondayMorning = moment('2015-02-23T10:00:00');
mondayMorning.isWorkingTime().should.be.false;
mondayMorning.clone().addWorkingTime(2, 'hours').format(full).should.equal('2015-02-23 14:00:00.000');
mondayMorning.clone().addWorkingTime(15, 'hours').format(full).should.equal('2015-02-25 12:30:00.000');
});
it('handles inconsistent closing hours', function () {
moment.locale('en', {
workinghours: {
0: null,
1: ['09:30:00', '17:00:00'],
2: ['09:30:00', '17:00:00'],
3: ['09:30:00', '13:00:00'],
4: ['09:30:00', '17:00:00'],
5: ['09:30:00', '17:00:00'],
6: null
}
});
var wednesdayAfternoon = moment('2015-02-25T16:00:00');
wednesdayAfternoon.isWorkingTime().should.be.false;
wednesdayAfternoon.clone().addWorkingTime(2, 'hours').format(full).should.equal('2015-02-26 11:30:00.000');
wednesdayAfternoon.clone().subtractWorkingTime(8, 'hours').format(full).should.equal('2015-02-24 12:30:00.000');
});
it('handles different working days', function () {
moment.locale('en', {
workinghours: {
0: ['09:30:00', '17:00:00'],
1: ['09:30:00', '17:00:00'],
2: ['09:30:00', '17:00:00'],
3: ['09:30:00', '17:00:00'],
4: ['09:30:00', '17:00:00'],
5: null,
6: null
}
});
var fridayAfternoon = moment('2015-02-27T16:00:00'),
sundayMorning = moment('2015-03-01T10:00:00');
fridayAfternoon.isWorkingTime().should.be.false;
fridayAfternoon.isWorkingDay().should.be.false;
sundayMorning.isWorkingTime().should.be.true;
sundayMorning.isWorkingDay().should.be.true;
sundayMorning.lastWorkingDay().format(date).should.equal('2015-02-26'); //thursday
});
});
});
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