-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New methods: addYearsToDate and getDateDiff
- Loading branch information
brencon
committed
Aug 29, 2015
1 parent
aaabda0
commit dc16a99
Showing
8 changed files
with
209 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var Intake = require('../index'); | ||
var intake = new Intake(); | ||
|
||
describe('#addYearsToDate', function() { | ||
it('add one year to a date', function() { | ||
var date = '1/1/2015'; | ||
var result = intake.addYearsToDate(date, 1); | ||
expect(result.toLocaleDateString("en-US")).to.equal('1/1/2016'); | ||
}); | ||
it('add ten years to a date', function() { | ||
var date = '9/1/2015'; | ||
var result = intake.addYearsToDate(date, 10); | ||
expect(result.toLocaleDateString("en-US")).to.equal('9/1/2025'); | ||
}); | ||
it('add minus one year to a date', function() { | ||
var date = '1/1/2015'; | ||
var result = intake.addYearsToDate(date, -1); | ||
expect(result.toLocaleDateString("en-US")).to.equal('1/1/2014'); | ||
}); | ||
it('expect a non-date to return the same value', function() { | ||
var date = 'test'; | ||
var result = intake.addYearsToDate(date, 1); | ||
expect(result).to.equal('test'); | ||
}); | ||
it('expect a date without years to add to be the same date', function() { | ||
var date = '9/1/2015'; | ||
var result = intake.addYearsToDate(date); | ||
expect(result.toLocaleDateString("en-US")).to.equal('9/1/2015'); | ||
}); | ||
}); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var Intake = require('../index'); | ||
var intake = new Intake(); | ||
|
||
describe('#getDateDiff', function() { | ||
it('return one second difference between two dates', function() { | ||
var d1 = new Date('2015', '9', '1', '10', '15', '30', '0'); | ||
var d2 = new Date('2015', '9', '1', '10', '15', '31', '0'); | ||
var result = intake.getDateDiff(d1, d2, 'seconds'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return negative one second difference between two dates', function() { | ||
var d1 = new Date('2015', '9', '1', '10', '15', '31', '0'); | ||
var d2 = new Date('2015', '9', '1', '10', '15', '30', '0'); | ||
var result = intake.getDateDiff(d1, d2, 'seconds'); | ||
expect(result).to.equal(-1); | ||
}); | ||
it('return one minute difference between two dates', function() { | ||
var d1 = new Date('2015', '9', '1', '10', '15', '30', '0'); | ||
var d2 = new Date('2015', '9', '1', '10', '16', '30', '0'); | ||
var result = intake.getDateDiff(d1, d2, 'minutes'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return one hour difference between two dates', function() { | ||
var d1 = new Date('2015', '9', '1', '10', '15', '30', '0'); | ||
var d2 = new Date('2015', '9', '1', '11', '15', '30', '0'); | ||
var result = intake.getDateDiff(d1, d2, 'hours'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return one day difference between two dates', function() { | ||
var d1 = '1/1/2015'; | ||
var d2 = '1/2/2015'; | ||
var result = intake.getDateDiff(d1, d2, 'days'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return one week difference between two dates', function() { | ||
var d1 = '1/1/2015'; | ||
var d2 = '1/8/2015'; | ||
var result = intake.getDateDiff(d1, d2, 'weeks'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return one month difference between two dates', function() { | ||
var d1 = '1/1/2015'; | ||
var d2 = '2/1/2015'; | ||
var result = intake.getDateDiff(d1, d2, 'months'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return one year difference between two dates', function() { | ||
var d1 = '1/1/2014'; | ||
var d2 = '1/1/2015'; | ||
var result = intake.getDateDiff(d1, d2, 'years'); | ||
expect(result).to.equal(1); | ||
}); | ||
it('return undefined if interval is unknown', function() { | ||
var d1 = '1/1/2014'; | ||
var d2 = '1/1/2015'; | ||
var result = intake.getDateDiff(d1, d2, 'test'); | ||
expect(result).to.equal(undefined); | ||
}); | ||
it('return NaN if one or both of the dates are not a date', function() { | ||
var d1 = '1/1/2014'; | ||
var d2 = 'test'; | ||
var result = intake.getDateDiff(d1, d2, 'days'); | ||
expect(isNaN(result)).to.equal(true); | ||
}); | ||
}); | ||
|
||
}()); |