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

moment-business

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-business - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

.jscsrc

2

bower.json
{
"name": "moment-business",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/jmeas/moment-business",

@@ -5,0 +5,0 @@ "authors": [

@@ -1,22 +0,6 @@

(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["moment", "contained-periodic-values"], factory);
} else if (typeof exports !== "undefined") {
var moment = require("moment");
var containedPeriodicValues = require("contained-periodic-values");
factory(moment, containedPeriodicValues);
} else {
factory(root.moment, root.containedPeriodicValues);
}
(function (global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(require("moment"), require("contained-periodic-values")) : typeof define === "function" && define.amd ? define(["moment", "contained-periodic-values"], factory) : factory(global.moment, global.containedPeriodicValues);
})(this, function (moment, containedPeriodicValues) {
"use strict";
var signPolyfill = function (x) {
x = +x;
if (x === 0 || isNaN(x)) {
return x;
}
return x > 0 ? 1 : -1;
};
moment.fn.weekDays = function (start) {

@@ -34,2 +18,10 @@ var startDay = start.day();

function signPolyfill(x) {
x = +x;
if (x === 0 || isNaN(x)) {
return x;
}
return x > 0 ? 1 : -1;
}
moment.fn.addWorkDays = function (count) {

@@ -72,3 +64,14 @@ if (count === 0) {

};
// Returns a Boolean representing
// whether or not the moment is Mon-Fri
moment.fn.isWorkDay = function () {
return this.isoWeekday() < 6;
};
// The inverse of the above method
moment.fn.isWeekendDay = function () {
return this.isoWeekday() > 5;
};
});
//# sourceMappingURL=moment-business.js.map
//# sourceMappingURL=./moment-business.js.map

@@ -1,2 +0,2 @@

!function(a,b){if("function"==typeof define&&define.amd)define(["moment","contained-periodic-values"],b);else if("undefined"!=typeof exports){var c=require("moment"),d=require("contained-periodic-values");b(c,d)}else b(a.moment,a.containedPeriodicValues)}(this,function(a,b){"use strict";var c=function(a){return a=+a,0===a||isNaN(a)?a:a>0?1:-1};a.fn.weekDays=function(a){var c=a.day(),d=Math.abs(this.diff(a,"days")),e=b(c,d+c,0,7),f=b(c,d+c,6,7);return d-(f+e)},a.fn.weekendDays=function(a){return Math.abs(this.diff(a,"days"))-this.weekDays(a)},a.fn.addWorkDays=function(a){if(0===a)return this;var b=c(a),d=this.day(),e=Math.abs(a),f=0;0===d&&-1===b?f=1:6===d&&1===b&&(f=1);var g=e;0!==d&&6!==d&&b>0?g+=d:0!==d&&6!==d&&0>b&&(g+=6-d);var h=Math.max(Math.floor(g/5)-1,0)+(g>5&&g%5>0?1:0);return f+=e+2*h,this.add(b*f,"days"),this},a.fn.subtractWorkDays=function(a){return this.addWorkDays(-a)}});
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(require("moment"),require("contained-periodic-values")):"function"==typeof define&&define.amd?define(["moment","contained-periodic-values"],b):b(a.moment,a.containedPeriodicValues)}(this,function(a,b){"use strict";function c(a){return a=+a,0===a||isNaN(a)?a:a>0?1:-1}a.fn.weekDays=function(a){var c=a.day(),d=Math.abs(this.diff(a,"days")),e=b(c,d+c,0,7),f=b(c,d+c,6,7);return d-(f+e)},a.fn.weekendDays=function(a){return Math.abs(this.diff(a,"days"))-this.weekDays(a)},a.fn.addWorkDays=function(a){if(0===a)return this;var b=c(a),d=this.day(),e=Math.abs(a),f=0;0===d&&-1===b?f=1:6===d&&1===b&&(f=1);var g=e;0!==d&&6!==d&&b>0?g+=d:0!==d&&6!==d&&0>b&&(g+=6-d);var h=Math.max(Math.floor(g/5)-1,0)+(g>5&&g%5>0?1:0);return f+=e+2*h,this.add(b*f,"days"),this},a.fn.subtractWorkDays=function(a){return this.addWorkDays(-a)},a.fn.isWorkDay=function(){return this.isoWeekday()<6},a.fn.isWeekendDay=function(){return this.isoWeekday()>5}});
//# sourceMappingURL=moment-business.min.js.map

@@ -5,3 +5,10 @@ var gulp = require('gulp');

});
const fs = require('fs');
const del = require('del');
const glob = require('glob');
const path = require('path');
const mkdirp = require('mkdirp');
const to5ify = require('6to5ify');
const isparta = require('isparta');
const esperanto = require('esperanto');
const browserify = require('browserify');

@@ -11,12 +18,15 @@ const runSequence = require('run-sequence');

// Adjust this file to configure the build
const config = require('./config');
const manifest = require('./package.json');
const config = manifest.to5BoilerplateOptions;
const mainFile = manifest.main;
const destinationFolder = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));
// Remove the built files
gulp.task('clean', function(cb) {
del([config.destinationFolder], cb);
del([destinationFolder], cb);
});
// Remove our temporary files
gulp.task('clean:tmp', function(cb) {
gulp.task('clean-tmp', function(cb) {
del(['tmp'], cb);

@@ -27,12 +37,21 @@ });

// so that you know your changes didn't build
function ding(file) {
function jshintNotify(file) {
if (!file.jshint) { return; }
return file.jshint.success ? false : 'JSHint failed';
};
}
function jscsNotify(file) {
if (!file.jscs) { return; }
return file.jscs.success ? false : 'JSRC failed';
}
// Lint our source code
gulp.task('lint:src', function() {
return gulp.src(['src/**/*.js', '!src/wrapper.js'])
gulp.task('lint-src', function() {
return gulp.src(['src/**/*.js'])
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(ding))
.pipe($.notify(jshintNotify))
.pipe($.jscs())
.pipe($.notify(jscsNotify))
.pipe($.jshint.reporter('fail'));

@@ -42,7 +61,10 @@ });

// Lint our test code
gulp.task('lint:test', function() {
return gulp.src(['test/unit/**/*.js'])
gulp.task('lint-test', function() {
return gulp.src(['test/**/*.js'])
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(ding))
.pipe($.notify(jshintNotify))
.pipe($.jscs())
.pipe($.notify(jscsNotify))
.pipe($.jshint.reporter('fail'));

@@ -52,36 +74,51 @@ });

// Build two versions of the library
gulp.task('build', ['lint:src', 'clean'], function() {
return gulp.src('src/wrapper.js')
.pipe($.template(config))
.pipe($.preprocess())
.pipe($.rename(config.exportFileName + '.js'))
.pipe($.sourcemaps.init())
.pipe($.to5({blacklist: ['useStrict'], modules: 'ignore'}))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(config.destinationFolder))
.pipe($.filter(['*', '!**/*.js.map']))
.pipe($.rename(config.exportFileName + '.min.js'))
.pipe($.uglifyjs({
outSourceMap: true,
inSourceMap: config.destinationFolder + '/' + config.exportFileName + '.js.map',
}))
.pipe(gulp.dest(config.destinationFolder));
});
gulp.task('build', ['lint-src', 'clean'], function(done) {
esperanto.bundle({
base: 'src',
entry: config.entryFileName,
}).then(function(bundle) {
var res = bundle.toUmd({
sourceMap: true,
sourceMapSource: config.entryFileName + '.js',
sourceMapFile: exportFileName + '.js',
name: config.exportVarName
});
// Use 6to5 to build the library to CommonJS modules. This
// is fed to Browserify, which builds the version of the lib
// for our browser spec runner.
gulp.task('compile_browser_script', function() {
return gulp.src(['src/**/*.js', '!src/wrapper.js'])
.pipe($.to5({modules: 'common'}))
.pipe(gulp.dest('tmp'))
.pipe($.filter([config.entryFileName + '.js']))
.pipe($.rename('__entry.js'))
.pipe(gulp.dest('tmp'));
// Write the generated sourcemap
mkdirp.sync(destinationFolder);
fs.writeFileSync(path.join(destinationFolder, exportFileName + '.js'), res.map.toString());
$.file(exportFileName + '.js', res.code, { src: true })
.pipe($.plumber())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.to5({ blacklist: ['useStrict'] }))
.pipe($.sourcemaps.write('./', {addComment: false}))
.pipe(gulp.dest(destinationFolder))
.pipe($.filter(['*', '!**/*.js.map']))
.pipe($.rename(exportFileName + '.min.js'))
.pipe($.uglifyjs({
outSourceMap: true,
inSourceMap: destinationFolder + '/' + exportFileName + '.js.map',
}))
.pipe(gulp.dest(destinationFolder))
.on('end', done);
});
});
// Bundle our app for our unit tests
gulp.task('browserify', ['compile_browser_script'], function() {
var bundleStream = browserify(['./test/setup/browserify.js']).bundle();
gulp.task('browserify', function() {
var testFiles = glob.sync('./test/unit/**/*');
var allFiles = ['./test/setup/browserify.js'].concat(testFiles);
var bundler = browserify(allFiles);
bundler.transform(to5ify.configure({
sourceMapRelative: __dirname + '/src',
blacklist: ['useStrict']
}));
var bundleStream = bundler.bundle();
return bundleStream
.on('error', function(err){
console.log(err.message);
this.emit('end');
})
.pipe($.plumber())
.pipe(source('./tmp/__spec-build.js'))

@@ -92,5 +129,13 @@ .pipe(gulp.dest(''))

function test() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.plumber())
.pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
}
gulp.task('coverage', function(done) {
gulp.src(['src/*.js', '!src/wrapper.js'])
.pipe($.istanbul())
gulp.src(['src/*.js'])
.pipe($.plumber())
.pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
.pipe($.istanbul.hookRequire())
.on('finish', function() {

@@ -103,10 +148,5 @@ return test()

function test() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
};
// Lint and run our tests
gulp.task('test', ['lint:src', 'lint:test'], function() {
require('6to5/register')({ modules: 'common' });
gulp.task('test', ['lint-src', 'lint-test'], function() {
require('6to5/register')({modules: 'common'});
return test();

@@ -117,17 +157,21 @@ });

// the build from breaking due to poorly formatted code.
gulp.task('build_in_sequence', function(callback) {
runSequence(['lint:src', 'lint:test'], 'browserify', callback);
gulp.task('build-in-sequence', function(callback) {
runSequence(['lint-src', 'lint-test'], 'browserify', callback);
});
// This is used when testing in the browser. Reloads the tests
// when the lib, or the tests themselves, change.
// Run the headless unit tests as you make changes.
gulp.task('watch', function() {
$.livereload.listen({port: 35729, host: 'localhost', start: true});
gulp.watch(['src/**/*.js', 'test/**/*', '.jshintrc', 'test/.jshintrc', 'config/index.json'], ['build_in_sequence']);
gulp.watch(['src/**/*', 'test/**/*', '.jshintrc', 'test/.jshintrc'], ['test']);
});
// Set up a livereload environment for our spec runner
gulp.task('test:browser', ['build_in_sequence', 'watch']);
gulp.task('test-browser', ['build-in-sequence'], function() {
$.livereload.listen({port: 35729, host: 'localhost', start: true});
return gulp.watch(
['src/**/*.js', 'test/**/*', '.jshintrc', 'test/.jshintrc'],
['build-in-sequence']
);
});
// An alias of test
gulp.task('default', ['test']);
{
"name": "moment-business",
"version": "1.0.1",
"version": "1.1.0",
"description": "Methods to work with week days and weekends in moment.",

@@ -32,10 +32,15 @@ "main": "dist/moment-business.js",

"devDependencies": {
"6to5": "^2.12.6",
"6to5": "^3.3.3",
"6to5ify": "^4.1.1",
"browserify": "^8.1.1",
"chai": "^1.10.0",
"del": "^1.1.1",
"esperanto": "^0.6.7",
"glob": "^4.3.5",
"gulp": "^3.8.10",
"gulp-6to5": "^2.0.2",
"gulp-6to5": "^3.0.0",
"gulp-file": "^0.2.0",
"gulp-filter": "^2.0.0",
"gulp-istanbul": "git://github.com/jmeas/gulp-istanbul.git#isparta",
"gulp-istanbul": "^0.6.0",
"gulp-jscs": "^1.4.0",
"gulp-jshint": "^1.9.0",

@@ -46,8 +51,9 @@ "gulp-livereload": "^3.4.0",

"gulp-notify": "^2.1.0",
"gulp-preprocess": "^1.2.0",
"gulp-plumber": "^0.6.6",
"gulp-rename": "^1.2.0",
"gulp-sourcemaps": "^1.3.0",
"gulp-template": "^2.0.0",
"gulp-uglifyjs": "^0.5.0",
"isparta": "^1.0.1",
"jshint-stylish": "^1.0.0",
"mkdirp": "^0.5.0",
"mocha": "^2.1.0",

@@ -64,3 +70,15 @@ "run-sequence": "^1.0.2",

"skipped-periodic-values": "0.0.1"
},
"to5BoilerplateOptions": {
"entryFileName": "moment-business",
"exportVarName": "none",
"mochaGlobals": [
"stub",
"spy",
"expect",
"moment",
"containedPeriodicValues",
"fixtures"
]
}
}

@@ -41,1 +41,9 @@ # moment-business

Subtract work days from the moment, modifying the original moment. Returns the moment.
##### `isWorkDay()`
Whether or not the Moment occurs between Monday and Friday.
##### `isWekendDay()`
Whether or not the Moment occurs on Saturday or Sunday.

@@ -61,1 +61,12 @@ import moment from 'moment';

};
// Returns a Boolean representing
// whether or not the moment is Mon-Fri
moment.fn.isWorkDay = function() {
return this.isoWeekday() < 6;
};
// The inverse of the above method
moment.fn.isWeekendDay = function() {
return this.isoWeekday() > 5;
};

@@ -5,3 +5,3 @@ global.fixtures = global.fixtures || {};

// The values are the amount added. The
// The values are the amount added. The
// keys are the resulting day

@@ -16,3 +16,3 @@ add.sunday = [

];
add.monday = [

@@ -25,3 +25,3 @@ '2015-03-02', '2015-03-03', '2015-03-04', '2015-03-05', '2015-03-06',

];
add.tuesday = [

@@ -34,3 +34,3 @@ '2015-03-03', '2015-03-04', '2015-03-05', '2015-03-06',

];
add.wednesday = [

@@ -43,3 +43,3 @@ '2015-03-04', '2015-03-05', '2015-03-06',

];
add.thursday = [

@@ -52,3 +52,3 @@ '2015-03-05', '2015-03-06',

];
add.friday = [

@@ -61,3 +61,3 @@ '2015-03-06',

];
add.saturday = [

@@ -64,0 +64,0 @@ '2015-03-07',

@@ -5,3 +5,3 @@ global.fixtures = global.fixtures || {};

// The values are the amount subtracted. The
// The values are the amount subtracted. The
// keys are the resulting day

@@ -8,0 +8,0 @@ subtract.sunday = [

global.fixtures = global.fixtures || {};
global.fixtures.friday = {
// Friday; same day

@@ -47,3 +47,3 @@ sameDay: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -86,3 +86,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -89,0 +89,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.monday = {
// Monday; same day

@@ -11,3 +11,3 @@ sameDay: {

},
// Monday => Tuesday

@@ -76,3 +76,3 @@ zeroWeeksMondayToTuesday: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -115,3 +115,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -118,0 +118,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.saturday = {
// Saturday; same day

@@ -40,3 +40,3 @@ sameDay: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -79,3 +79,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -82,0 +82,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.sunday = {
// Sunday; same day

@@ -18,3 +18,3 @@ sameDay: {

},
// Sunday => Tuesday

@@ -83,3 +83,3 @@ zeroWeeksSundayToTuesday: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -122,3 +122,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -125,0 +125,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.thursday = {
// Thursday; same day

@@ -54,3 +54,3 @@ sameDay: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -93,3 +93,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -96,0 +96,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.tuesday = {
// Tuesday; same day

@@ -68,3 +68,3 @@ sameDay: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -107,3 +107,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -110,0 +110,0 @@

global.fixtures = global.fixtures || {};
global.fixtures.wednesday = {
// Wednesday; same day

@@ -61,3 +61,3 @@ sameDay: {

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -100,3 +100,3 @@

// ...skipping ahead to the next interesting
// Skipping ahead to the next interesting
// datapoint

@@ -103,0 +103,0 @@

@@ -1,3 +0,3 @@

var setup = require('./setup');
var config = require('../../config');
var config = require('../../package.json').to5BoilerplateOptions;
global._ = require('underscore');

@@ -15,3 +15,2 @@ require('../fixtures/work-diff/sunday');

global.moment = require('moment');
require('../../tmp/__entry');
global.mocha.setup('bdd');

@@ -22,3 +21,3 @@ global.onload = function() {

global.mocha.run();
setup();
require('./setup')();
};

@@ -1,3 +0,1 @@

var setup = require('./setup');
var config = require('../../config');
global._ = require('underscore');

@@ -14,7 +12,7 @@ require('../fixtures/work-diff/sunday');

require('6to5/register');
global.moment = require('moment');
require('../../src/' + config.entryFileName);
global.chai = require('chai');
global.sinon = require('sinon');
global.chai.use(require('sinon-chai'));
setup();
require('./setup')();

@@ -15,2 +15,2 @@ module.exports = function() {

});
}
};

@@ -0,157 +1,160 @@

import '../../src/moment-business';
var DATE_FORMAT = 'YYYY-MM-DD';
var start, calculated;
describe('Adding weekdays', function() {
describe('starting at Sunday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-01', DATE_FORMAT);
describe('Adding weekdays', () => {
describe('starting at Sunday', () => {
beforeEach(() => {
start = moment.utc('2015-03-01', DATE_FORMAT);
});
_.each(fixtures.add.sunday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition + '.', function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.sunday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition + '.', () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.sunday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.sunday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Monday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-02', DATE_FORMAT);
describe('starting at Monday', () => {
beforeEach(() => {
start = moment.utc('2015-03-02', DATE_FORMAT);
});
_.each(fixtures.add.monday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.monday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.monday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.monday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Tuesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-03', DATE_FORMAT);
describe('starting at Tuesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-03', DATE_FORMAT);
});
_.each(fixtures.add.tuesday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.tuesday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.tuesday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.tuesday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Wednesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-04', DATE_FORMAT);
describe('starting at Wednesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-04', DATE_FORMAT);
});
_.each(fixtures.add.wednesday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.wednesday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.wednesday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.wednesday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Thursday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-05', DATE_FORMAT);
describe('starting at Thursday', () => {
beforeEach(() => {
start = moment.utc('2015-03-05', DATE_FORMAT);
});
_.each(fixtures.add.thursday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.thursday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.thursday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.thursday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Friday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-06', DATE_FORMAT);
describe('starting at Friday', () => {
beforeEach(() => {
start = moment.utc('2015-03-06', DATE_FORMAT);
});
_.each(fixtures.add.friday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.friday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.friday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.friday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Saturday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-07', DATE_FORMAT);
describe('starting at Saturday', () => {
beforeEach(() => {
start = moment.utc('2015-03-07', DATE_FORMAT);
});
_.each(fixtures.add.saturday, function(solution, addition) {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition + '.', function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.saturday, (solution, addition) => {
it('when adding, should calculate the correct number of workdays between every two dates; ' + addition + '.', () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.add.saturday, function(solution, addition) {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.add.saturday, (solution, addition) => {
it('when subtracting negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
});

@@ -0,157 +1,160 @@

import '../../src/moment-business';
var DATE_FORMAT = 'YYYY-MM-DD';
var start, calculated;
describe('Subtracting / adding negative weekdays', function() {
describe('starting at Sunday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-05', DATE_FORMAT);
describe('Subtracting / adding negative weekdays', () => {
describe('starting at Sunday', () => {
beforeEach(() => {
start = moment.utc('2015-04-05', DATE_FORMAT);
});
_.each(fixtures.subtract.sunday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition + '.', function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.sunday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition + '.', () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.sunday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition + '.', function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.sunday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition + '.', () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Monday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-06', DATE_FORMAT);
describe('starting at Monday', () => {
beforeEach(() => {
start = moment.utc('2015-04-06', DATE_FORMAT);
});
_.each(fixtures.subtract.monday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.monday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.monday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.monday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Tuesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-07', DATE_FORMAT);
describe('starting at Tuesday', () => {
beforeEach(() => {
start = moment.utc('2015-04-07', DATE_FORMAT);
});
_.each(fixtures.subtract.tuesday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.tuesday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.tuesday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.tuesday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Wednesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-08', DATE_FORMAT);
describe('starting at Wednesday', () => {
beforeEach(() => {
start = moment.utc('2015-04-08', DATE_FORMAT);
});
_.each(fixtures.subtract.wednesday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.wednesday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.wednesday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.wednesday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Thursday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-09', DATE_FORMAT);
describe('starting at Thursday', () => {
beforeEach(() => {
start = moment.utc('2015-04-09', DATE_FORMAT);
});
_.each(fixtures.subtract.thursday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.thursday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.thursday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.thursday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Friday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-10', DATE_FORMAT);
describe('starting at Friday', () => {
beforeEach(() => {
start = moment.utc('2015-04-10', DATE_FORMAT);
});
_.each(fixtures.subtract.friday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.friday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.friday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.friday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
describe('starting at Saturday', function() {
beforeEach(function() {
this.start = moment.utc('2015-04-11', DATE_FORMAT);
describe('starting at Saturday', () => {
beforeEach(() => {
start = moment.utc('2015-04-11', DATE_FORMAT);
});
_.each(fixtures.subtract.saturday, function(solution, addition) {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).subtractWorkDays(addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.saturday, (solution, addition) => {
it('when subtracting, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).subtractWorkDays(addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
_.each(fixtures.subtract.saturday, function(solution, addition) {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, function() {
this.solution = moment(solution, DATE_FORMAT);
this.calculated = moment(this.start).addWorkDays(-addition);
expect(this.calculated.isSame(this.solution, 'day')).to.be.true;
_.each(fixtures.subtract.saturday, (solution, addition) => {
it('when adding negative, should calculate the correct number of workdays between every two dates; ' + addition, () => {
solution = moment(solution, DATE_FORMAT);
calculated = moment(start).addWorkDays(-addition);
expect(calculated.isSame(solution, 'day')).to.be.true;
});
}, this);
});
});
});

@@ -0,101 +1,104 @@

import '../../src/moment-business';
var DATE_FORMAT = 'YYYY-MM-DD';
var start, endMoment, weekDays;
describe('Week day count', function() {
describe('starting at Sunday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-01', DATE_FORMAT);
describe('Week day count', () => {
describe('starting at Sunday', () => {
beforeEach(() => {
start = moment.utc('2015-03-01', DATE_FORMAT);
});
_.each(fixtures.sunday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.sunday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Monday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-02', DATE_FORMAT);
describe('starting at Monday', () => {
beforeEach(() => {
start = moment.utc('2015-03-02', DATE_FORMAT);
});
_.each(fixtures.monday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.monday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Tuesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-03', DATE_FORMAT);
describe('starting at Tuesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-03', DATE_FORMAT);
});
_.each(fixtures.tuesday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.tuesday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Wednesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-04', DATE_FORMAT);
describe('starting at Wednesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-04', DATE_FORMAT);
});
_.each(fixtures.wednesday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.wednesday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Thursday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-05', DATE_FORMAT);
describe('starting at Thursday', () => {
beforeEach(() => {
start = moment.utc('2015-03-05', DATE_FORMAT);
});
_.each(fixtures.thursday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.thursday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Friday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-06', DATE_FORMAT);
describe('starting at Friday', () => {
beforeEach(() => {
start = moment.utc('2015-03-06', DATE_FORMAT);
});
_.each(fixtures.friday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.friday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
describe('starting at Saturday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-07', DATE_FORMAT);
describe('starting at Saturday', () => {
beforeEach(() => {
start = moment.utc('2015-03-07', DATE_FORMAT);
});
_.each(fixtures.saturday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekDays);
_.each(fixtures.saturday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekDays = endMoment.weekDays(start);
expect(weekDays).to.equal(fixture.weekDays);
});
}, this);
});
});
});

@@ -0,101 +1,104 @@

import '../../src/moment-business';
var DATE_FORMAT = 'YYYY-MM-DD';
var start, endMoment, weekendDays;
describe('Weekend day count', function() {
describe('starting at Sunday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-01', DATE_FORMAT);
describe('Weekend day count', () => {
describe('starting at Sunday', () => {
beforeEach(() => {
start = moment.utc('2015-03-01', DATE_FORMAT);
});
_.each(fixtures.sunday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.sunday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Monday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-02', DATE_FORMAT);
describe('starting at Monday', () => {
beforeEach(() => {
start = moment.utc('2015-03-02', DATE_FORMAT);
});
_.each(fixtures.monday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.monday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Tuesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-03', DATE_FORMAT);
describe('starting at Tuesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-03', DATE_FORMAT);
});
_.each(fixtures.tuesday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.tuesday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Wednesday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-04', DATE_FORMAT);
describe('starting at Wednesday', () => {
beforeEach(() => {
start = moment.utc('2015-03-04', DATE_FORMAT);
});
_.each(fixtures.wednesday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.wednesday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Thursday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-05', DATE_FORMAT);
describe('starting at Thursday', () => {
beforeEach(() => {
start = moment.utc('2015-03-05', DATE_FORMAT);
});
_.each(fixtures.thursday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.thursday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Friday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-06', DATE_FORMAT);
describe('starting at Friday', () => {
beforeEach(() => {
start = moment.utc('2015-03-06', DATE_FORMAT);
});
_.each(fixtures.friday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.friday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
describe('starting at Saturday', function() {
beforeEach(function() {
this.start = moment.utc('2015-03-07', DATE_FORMAT);
describe('starting at Saturday', () => {
beforeEach(() => {
start = moment.utc('2015-03-07', DATE_FORMAT);
});
_.each(fixtures.saturday, function(fixture, description) {
it('should calculate the correct number of workdays between every two dates; ' + description, function() {
this.endMoment = moment(this.start).utc().add(fixture.duration, 'days');
this.weekendDays = this.endMoment.weekendDays(this.start);
expect(this.weekendDays).to.equal(fixture.weekendDays);
_.each(fixtures.saturday, (fixture, description) => {
it('should calculate the correct number of workdays between every two dates; ' + description, () => {
endMoment = moment(start).utc().add(fixture.duration, 'days');
weekendDays = endMoment.weekendDays(start);
expect(weekendDays).to.equal(fixture.weekendDays);
});
}, this);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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