Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

kill Date#toISOString shim

Christopher Hiller7af6611d3e99
diff --git a/.eslintignore b/.eslintignore
index 7adc61c7..71944945 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,5 +1,4 @@
coverage/
-lib/to-iso-string/**/*.js
mocha.js
BUILDTMP
*.fixture.js
diff --git a/lib/to-iso-string/LICENSE b/lib/to-iso-string/LICENSE
deleted file mode 100644
index c25db565..00000000
--- a/lib/to-iso-string/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2016 Segment.io, Inc. ([email protected])
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/lib/to-iso-string/index.js b/lib/to-iso-string/index.js
deleted file mode 100644
index cd28d7be..00000000
--- a/lib/to-iso-string/index.js
+++ /dev/null
@@ -1,37 +0,0 @@
-'use strict';
-
-/**
- * Pad a `number` with a ten's place zero.
- *
- * @param {number} number
- * @return {string}
- */
-function pad(number) {
- var n = number.toString();
- return n.length === 1 ? '0' + n : n;
-}
-
-/**
- * Turn a `date` into an ISO string.
- *
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
- *
- * @param {Date} date
- * @return {string}
- */
-function toISOString(date) {
- return date.getUTCFullYear()
- + '-' + pad(date.getUTCMonth() + 1)
- + '-' + pad(date.getUTCDate())
- + 'T' + pad(date.getUTCHours())
- + ':' + pad(date.getUTCMinutes())
- + ':' + pad(date.getUTCSeconds())
- + '.' + String((date.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5)
- + 'Z';
-}
-
-/*
- * Exports.
- */
-
-module.exports = toISOString;
diff --git a/lib/utils.js b/lib/utils.js
index 2770a1f1..2c67cdc6 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -16,7 +16,6 @@ var readdirSync = require('fs').readdirSync;
var statSync = require('fs').statSync;
var watchFile = require('fs').watchFile;
var lstatSync = require('fs').lstatSync;
-var toISOString = require('./to-iso-string');
var he = require('he');
/**
@@ -349,12 +348,7 @@ function jsonStringify (object, spaces, depth) {
: val.toString();
break;
case 'date':
- var sDate;
- if (isNaN(val.getTime())) { // Invalid date
- sDate = val.toString();
- } else {
- sDate = val.toISOString ? val.toISOString() : toISOString(val);
- }
+ var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
val = '[Date: ' + sDate + ']';
break;
case 'buffer':
diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.js
index 080ddcb9..7c4313ff 100644
--- a/test/unit/utils.spec.js
+++ b/test/unit/utils.spec.js
@@ -1,7 +1,6 @@
'use strict';
var utils = require('../../lib/utils');
-var toISOString = require('../../lib/to-iso-string');
describe('lib/utils', function () {
describe('clean', function () {
@@ -170,18 +169,10 @@ describe('lib/utils', function () {
});
it('should return Date object with .toISOString() + string prefix', function () {
- expect(stringify(new Date(0))).to.equal('[Date: ' + shimToISOString(new Date(0)) + ']');
+ expect(stringify(new Date(0))).to.equal('[Date: ' + new Date(0).toISOString() + ']');
var date = new Date(); // now
- expect(stringify(date)).to.equal('[Date: ' + shimToISOString(date) + ']');
-
- function shimToISOString (date) {
- if (date.toISOString) {
- return date.toISOString();
- } else {
- return toISOString(date);
- }
- }
+ expect(stringify(date)).to.equal('[Date: ' + date.toISOString() + ']');
});
it('should return invalid Date object with .toString() + string prefix', function () {