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

chai-datetime

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-datetime - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

33

chai-datetime.js

@@ -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 @@

5

package.json
{
"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

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