chai-datetime
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -24,2 +24,28 @@ (function(plugin){ | ||
function padNumber(num, length) { | ||
var ret = '' + num; | ||
var i = ret.length; | ||
if (!isFinite(length)) { | ||
length = 2; | ||
} | ||
for (i; i < length; i++) { | ||
ret = '0' + ret; | ||
} | ||
return ret; | ||
} | ||
chai.datetime.getFormattedTimezone = function(timezoneInMinutes) { | ||
var tz = Math.abs(timezoneInMinutes); | ||
var hours = Math.floor(tz / 60); | ||
var minutes = tz % 60; | ||
var isAheadOfUtc = timezoneInMinutes <= 0; | ||
return (isAheadOfUtc ? '+' : '-') + | ||
padNumber(hours) + ':' + | ||
padNumber(minutes); | ||
} | ||
chai.datetime.formatDate = function(date) { | ||
@@ -30,3 +56,8 @@ return date.toDateString(); | ||
chai.datetime.formatTime = function(time) { | ||
return time; | ||
return time.toDateString() + ' ' + | ||
padNumber(time.getHours()) + ':' + | ||
padNumber(time.getMinutes()) + ':' + | ||
padNumber(time.getSeconds()) + '.' + | ||
padNumber(time.getMilliseconds(), 3) + ' (' + | ||
chai.datetime.getFormattedTimezone(time.getTimezoneOffset()) + ')'; | ||
}; | ||
@@ -33,0 +64,0 @@ |
{ | ||
"name": "chai-datetime", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"keywords": ["chai", "testing", "jasmine"], | ||
@@ -21,3 +21,2 @@ "description": "date / time comparison matchers for chai", | ||
"devDependencies": { | ||
"chai": "^1.9.0", | ||
"mocha": "~1.6.0", | ||
@@ -27,4 +26,4 @@ "nodemon": "~0.6.23" | ||
"dependencies": { | ||
"chai": "^1.9.0" | ||
"chai": ">1.9.0" | ||
} | ||
} |
@@ -25,3 +25,3 @@ # chai-datetime | ||
AssertionError: expected Thu May 30 2013 16:06:00 GMT-0400 (EDT) to equal Thu May 30 2013 16:05:00 GMT-0400 (EDT) | ||
AssertionError: expected Thu May 30 2013 16:06:00.000 (-04:00) to equal Thu May 30 2013 16:05:00.000 (-04:00) | ||
@@ -28,0 +28,0 @@ ## Usage |
@@ -10,3 +10,3 @@ (function(test){ | ||
var chai = require('chai'); | ||
chai.Assertion.includeStack = true; | ||
chai.config.includeStack = true; | ||
test(chai, true); | ||
@@ -395,3 +395,2 @@ }()); | ||
describe('beforeTime', function() { | ||
@@ -445,3 +444,2 @@ describe('when comparing two different times', function() { | ||
describe('afterTime', function() { | ||
@@ -495,3 +493,80 @@ describe('when comparing two different times', function() { | ||
describe('formatTime', function() { | ||
describe('printing the date at the start', function() { | ||
it('prints the date at the beginning of the string', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 345); | ||
chai.datetime.formatTime(date).should.match(/^Sat Dec 20 2014.*/); | ||
}); | ||
}); | ||
describe('printing the time', function() { | ||
it('prints milliseconds with one digit', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 002); | ||
chai.datetime.formatTime(date).should.match(/.*15:20:17\.002.*/); | ||
}); | ||
it('prints milliseconds with two digits', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 097); | ||
chai.datetime.formatTime(date).should.match(/.*15:20:17\.097.*/); | ||
}); | ||
it('prints milliseconds with three digits', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 17, 345); | ||
chai.datetime.formatTime(date).should.match(/.*15:20:17\.345.*/); | ||
}); | ||
it('prints seconds with one digit', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 7, 345); | ||
chai.datetime.formatTime(date).should.match(/.*15:20:07.*/); | ||
}); | ||
it('prints seconds with two digits', function() { | ||
var date = new Date(2014, 11, 20, 15, 20, 49, 345); | ||
chai.datetime.formatTime(date).should.match(/.*15:20:49.*/); | ||
}); | ||
it('prints minutes with one digit', function() { | ||
var date = new Date(2014, 11, 20, 15, 6, 49, 345); | ||
chai.datetime.formatTime(date).should.match(/.*15:06:49.*/); | ||
}); | ||
it('prints minutes with two digits', function() { | ||
var date = new Date(2014, 11, 20, 15, 31, 49, 345); | ||
chai.datetime.formatTime(date).should.match(/.*15:31:49.*/); | ||
}); | ||
it('prints hours with one digit', function() { | ||
var date = new Date(2014, 11, 20, 3, 20, 49, 345); | ||
chai.datetime.formatTime(date).should.match(/.*03:20:49.*/); | ||
}); | ||
it('prints hours with two digits', function() { | ||
var date = new Date(2014, 11, 20, 17, 20, 49, 345); | ||
chai.datetime.formatTime(date).should.match(/.*17:20:49.*/); | ||
}); | ||
}); | ||
describe('printing the timezone', function() { | ||
it('prints the local timezone', function() { | ||
var date = new Date('2014-12-20T15:20:17.345Z'); | ||
chai.datetime.formatTime(date).should.match(/.* \([+-]\d\d:\d\d\)$/); | ||
}); | ||
}); | ||
}); | ||
describe('getFormattedTimezone', function() { | ||
// Note, timezone is given in minutes, negative means it is ahead of UTC. | ||
it('should use a + to indicate the timezone is ahead of UTC', function () { | ||
chai.datetime.getFormattedTimezone(-525).should.equal('+08:45'); | ||
}); | ||
it('should use a - to indicate the timezone is behind of UTC', function () { | ||
chai.datetime.getFormattedTimezone(300).should.equal('-05:00'); | ||
}); | ||
it('should use a + when we are in the UTC timezone', function () { | ||
chai.datetime.getFormattedTimezone(0).should.equal('+00:00'); | ||
}) | ||
}); | ||
describe('tdd alias', function() { | ||
@@ -498,0 +573,0 @@ beforeEach(function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30198
2
678
+ Addedassertion-error@2.0.1(transitive)
+ Addedchai@5.1.2(transitive)
+ Addedcheck-error@2.1.1(transitive)
+ Addeddeep-eql@5.0.2(transitive)
+ Addedloupe@3.1.2(transitive)
+ Addedpathval@2.0.0(transitive)
- Removedassertion-error@1.0.0(transitive)
- Removedchai@1.10.0(transitive)
- Removeddeep-eql@0.1.3(transitive)
- Removedtype-detect@0.1.1(transitive)
Updatedchai@>1.9.0