pax_global_header00006660000000000000000000000064133663545170014527gustar00rootroot0000000000000052 comment=170f16b6763aaf5b02992a1ea8ddf2504469c938 duration-0.2.2/000077500000000000000000000000001336635451700133555ustar00rootroot00000000000000duration-0.2.2/.editorconfig000066400000000000000000000004201336635451700160260ustar00rootroot00000000000000# EditorConfig is awesome: http://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true indent_style = tab [{*.json,*.yml}] indent_style = space indent_size = 2 duration-0.2.2/.gitignore000066400000000000000000000000601336635451700153410ustar00rootroot00000000000000/node_modules /npm-debug.log /package-lock.json duration-0.2.2/CHANGELOG.md000066400000000000000000000012641336635451700151710ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ## [0.2.2](https://github.com/medikoo/duration/compare/v0.2.1...v0.2.2) (2018-10-31) ### Bug Fixes * fix duration.day calculation for uneven months ([c63bcfa](https://github.com/medikoo/duration/commit/c63bcfa)) ## [0.2.1](https://github.com/medikoo/duration/compare/v0.2.0...v0.2.1) (2018-08-31) - Fix spelling LICENCE - LICENSE (Addresses https://github.com/medikoo/duration/issues/5) - Reconfigure to use eslint ## Old changelog See `CHANGES` duration-0.2.2/CHANGES000066400000000000000000000011571336635451700143540ustar00rootroot00000000000000-- For new changelog see CHANGELOG.md v0.2.0 -- 2014.04.27 * Move main module from lib/duration.js to index.js * Remove Makefile (it's cross environment package) * Update to use latest versions of dependencies v0.1.4 -- 2013.01.03 * Threshold option for default toString modes v0.1.3 -- 2013.01.02 * Fix documentation of npm install command v0.1.2 -- 2012.11.10 * Fix handling of negative durations (when to is older than from) v0.1.1 -- 2012.10.04 Maintanance * Rename lib/index.js to lib/duration.js * Lint cleanup * Upgrade es5-ext v0.1.0 -- 2012.05.28 * Initial version (derived from es5-ext project) duration-0.2.2/LICENSE000066400000000000000000000014051336635451700143620ustar00rootroot00000000000000ISC License Copyright (c) 2012-2018, Mariusz Nowak, @medikoo, medikoo.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. duration-0.2.2/README.md000066400000000000000000000112451336635451700146370ustar00rootroot00000000000000[![*nix build status][nix-build-image]][nix-build-url] [![Windows build status][win-build-image]][win-build-url] ![Transpilation status][transpilation-image] [![npm version][npm-image]][npm-url] # duration - Time duration utilities _Formerly part of [es5-ext](https://github.com/medikoo/es5-ext) project._ ## Installation ### Node.js $ npm install duration ### Browser Can be bundled for browser with help of [modules-webmake](https://github.com/medikoo/modules-webmake) ## Example usage: ```javascript var Duration = require("duration"); var duration = new Duration(new Date(2000, 6, 7), new Date(2010, 8, 13, 3, 23, 8, 456)); console.log("Years: ", duration.years); console.log("Months: ", duration.months); console.log("Days: ", duration.days); console.log("Hours: ", duration.hours); console.log("Minutes: ", duration.minutes); console.log("Seconds: ", duration.seconds); console.log("Milliseconds: ", duration.milliseconds); console.log("Trailing months: ", duration.month); console.log("Trailing days: ", duration.day); console.log("Trailing hours: ", duration.hour); console.log("Trailing minutes: ", duration.minute); console.log("Trailing seconds: ", duration.second); console.log("Trailing milliseconds: ", duration.millisecond); console.log("Default string representation: ", duration.toString()); console.log("Alternative string representation: ", duration.toString(1)); console.log("Custom string representation: ", duration.toString("H: %Hs m: %M")); ``` Output: ``` Years: 10 Months: 122 Days: 3720 Hours: 89283 Minutes: 5357003 Seconds: 321420188 Milliseconds: 321420188456 Trailing months: 2 Trailing days: 6 Trailing hours: 3 Trailing minutes: 23 Trailing seconds: 8 Trailing milliseconds: 456 Default string representation: 10y 2m 6d 03:23:08.456 Alternative string representation: 10y 2m 6d 3h 23m 8s 456ms Custom string representation: H: 89283 m: 23 ``` ## Duration(from[, to]) Main module is both constructor and factory method, and can be used either way. `from` and `to` are expected to be JavaScript Date objects. `to` is optional, and if not provided it defaults to current time. ## Duration.prototype properties ### years Returns full years of the duration ### months Returns full months of the duration ### days Returns full days of the duration ### hours Returns full hours of the duration ### seconds Returns full seconds of the duration ### minutes Returns full minutes of the duration ### milliseconds Returns milliseconds of the duration ### year Same as `years`. Returns full years of the duration ### month Returns trailing months of the duration ### day Returns trailing days of the duration ### hour Returns trailing hours of the duration ### minute Returns trailing minutes of the duration ### second Returns trailing seconds of the duration ### millisecond Returns trailing seconds of the duration ## valueOf() Same as `milliseconds`. Returns milliseconds of the duration ## toString([mode[, threshold]]) Returns readable representation of the duration. When invoked without arguments (defaults to _mode=0_), returns as: 10y 2m 6d 03:23:08.456 When invoked with mode `1`, returns alternative representation: 10y 2m 6d 3h 23m 8s 456ms Representation returned by default modes can be customized with threshold setting that trims lowest units: ```javascript duration.toString(); // 10y 2m 6d 03:23:08.456 duration.toString(0, 1); // 10y 2m 6d 03:23:08 duration.toString(0, 2); // 10y 2m 6d 03:23 duration.toString(1); // 10y 2m 6d 3h 23m 8s 456ms duration.toString(1, 1); // 10y 2m 6d 3h 23m 8s duration.toString(1, 2); // 10y 2m 6d 3h 23m ``` ## toString(format) When invoked with string, formats the duration according to given pattern, where: - `%y` - `duration.year` - `%m` - `duration.month` - `%d` - `duration.day` - `%H` - `duration.hour` - `%M` - `duration.minute` - `%S` - `duration.second` - `%L` - `duration.millisecond` - `%ms` - `duration.months` - `%ds` - `duration.days` - `%Hs` - `duration.hours` - `%Ms` - `duration.minutes` - `%Ss` - `duration.seconds` - `%Ls` - `duration.milliseconds` - `%sign` - If duration is negative outputs `-` otherwise empty string ## Tests $ npm test [nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/duration/branches/master/shields_badge.svg [nix-build-url]: https://semaphoreci.com/medikoo-org/duration [win-build-image]: https://ci.appveyor.com/api/projects/status/nt9c72n1ay9coree?svg=true [win-build-url]: https://ci.appveyor.com/project/medikoo/duration [transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg [npm-image]: https://img.shields.io/npm/v/duration.svg [npm-url]: https://www.npmjs.com/package/duration duration-0.2.2/index.js000066400000000000000000000160031336635451700150220ustar00rootroot00000000000000"use strict"; var d = require("d") , pad = require("es5-ext/number/#/pad") , date = require("es5-ext/date/valid-date") , daysInMonth = require("es5-ext/date/#/days-in-month") , copy = require("es5-ext/date/#/copy") , dfloor = require("es5-ext/date/#/floor-day") , mfloor = require("es5-ext/date/#/floor-month") , yfloor = require("es5-ext/date/#/floor-year") , toInteger = require("es5-ext/number/to-integer") , toPosInt = require("es5-ext/number/to-pos-integer") , isValue = require("es5-ext/object/is-value"); var abs = Math.abs, format, toPrimitive, getYear, Duration, getCalcData; format = require("es5-ext/string/format-method")({ y: function () { return String(abs(this.year)); }, m: function () { return pad.call(abs(this.month), 2); }, d: function () { return pad.call(abs(this.day), 2); }, H: function () { return pad.call(abs(this.hour), 2); }, M: function () { return pad.call(abs(this.minute), 2); }, S: function () { return pad.call(abs(this.second), 2); }, L: function () { return pad.call(abs(this.millisecond), 3); }, ms: function () { return String(abs(this.months)); }, ds: function () { return String(abs(this.days)); }, Hs: function () { return String(abs(this.hours)); }, Ms: function () { return String(abs(this.minutes)); }, Ss: function () { return String(abs(this.seconds)); }, Ls: function () { return String(abs(this.milliseconds)); }, sign: function () { return this.to < this.from ? "-" : ""; } }); getCalcData = function (duration) { return duration.to < duration.from ? { to: duration.from, from: duration.to, sign: -1 } : { to: duration.to, from: duration.from, sign: 1 }; }; Duration = module.exports = function (from, to) { // Make it both constructor and factory if (!(this instanceof Duration)) return new Duration(from, to); this.from = date(from); this.to = isValue(to) ? date(to) : new Date(); }; Duration.prototype = Object.create(Object.prototype, { valueOf: d((toPrimitive = function () { return this.to - this.from; })), millisecond: d.gs(function () { return this.milliseconds % 1000; }), second: d.gs(function () { return this.seconds % 60; }), minute: d.gs(function () { return this.minutes % 60; }), hour: d.gs(function () { return this.hours % 24; }), day: d.gs(function () { var data = getCalcData(this); var toDays = data.to.getDate(), fromDays = data.from.getDate(); var isToLater = data.to - dfloor.call(copy.call(data.to)) >= data.from - dfloor.call(copy.call(data.from)); var result; if (toDays > fromDays) { result = toDays - fromDays; if (!isToLater) --result; return data.sign * result; } if (toDays === fromDays && isToLater) { return 0; } result = isToLater ? toDays : toDays - 1; result += daysInMonth.call(data.from) - data.from.getDate(); return data.sign * result; }), month: d.gs(function () { var data = getCalcData(this); return ( data.sign * (((12 - data.from.getMonth() + data.to.getMonth()) % 12) - (data.from - mfloor.call(copy.call(data.from)) > data.to - mfloor.call(copy.call(data.to)))) ); }), year: d.gs( (getYear = function () { var data = getCalcData(this); return ( data.sign * (data.to.getFullYear() - data.from.getFullYear() - (data.from - yfloor.call(copy.call(data.from)) > data.to - yfloor.call(copy.call(data.to)))) ); }) ), milliseconds: d.gs(toPrimitive, null), seconds: d.gs(function () { return toInteger(this.valueOf() / 1000); }), minutes: d.gs(function () { return toInteger(this.valueOf() / (1000 * 60)); }), hours: d.gs(function () { return toInteger(this.valueOf() / (1000 * 60 * 60)); }), days: d.gs(function () { return toInteger(this.valueOf() / (1000 * 60 * 60 * 24)); }), months: d.gs(function () { var data = getCalcData(this); return ( data.sign * ((data.to.getFullYear() - data.from.getFullYear()) * 12 + data.to.getMonth() - data.from.getMonth() - (data.from - mfloor.call(copy.call(data.from)) > data.to - mfloor.call(copy.call(data.to)))) ); }), years: d.gs(getYear), _resolveSign: d(function (isNonZero) { if (!isNonZero) return ""; return this.to < this.from ? "-" : ""; }), _toStringDefaultDate: d(function (threshold, s, isNonZero) { if (!this.days && threshold < 0) return this._resolveSign(isNonZero) + s; if (threshold-- <= 0) s = abs((isNonZero = this.day)) + "d" + (s ? " " : "") + s; if (!this.months && threshold < 0) return this._resolveSign(isNonZero) + s; if (threshold-- <= 0) s = abs((isNonZero = this.month)) + "m" + (s ? " " : "") + s; if (this.years || threshold >= 0) { s = abs((isNonZero = this.year)) + "y" + (s ? " " : "") + s; } return this._resolveSign(isNonZero) + s; }), _toStringDefault: d(function (threshold) { var s = "", isNonZero; if (threshold-- <= 0) s += "." + pad.call(abs((isNonZero = this.millisecond)), 3); if (!this.seconds && threshold < 0) return this._resolveSign(isNonZero) + s; if (threshold-- <= 0) { isNonZero = this.second; s = (this.minutes ? pad.call(abs(isNonZero), 2) : abs(isNonZero)) + s; } if (!this.minutes && threshold < 0) return this._resolveSign(isNonZero) + s; if (threshold-- <= 0) { isNonZero = this.minute; s = (this.hours || s ? pad.call(abs(isNonZero), 2) : abs(isNonZero)) + (s ? ":" : "") + s; } if (!this.hours && threshold < 0) return this._resolveSign(isNonZero) + s; if (threshold-- <= 0) s = pad.call(abs((isNonZero = this.hour)), 2) + (s ? ":" : "") + s; return this._toStringDefaultDate(threshold, s, isNonZero); }), _toString1: d(function (threshold) { var tokens = [], isNonZero; if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.millisecond)) + "ms"); if (!this.seconds && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.second)) + "s"); if (!this.minutes && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.minute)) + "m"); if (!this.hours && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.hour)) + "h"); if (!this.days && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.day)) + "d"); if (!this.months && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); if (threshold-- <= 0) tokens.unshift(abs((isNonZero = this.month)) + "m"); if (!this.years && threshold < 0) return this._resolveSign(isNonZero) + tokens.join(" "); tokens.unshift(abs((isNonZero = this.year)) + "y"); return this._resolveSign(isNonZero) + tokens.join(" "); }), toString: d(function (pattern/*, threshold*/) { var threshold; if (!isValue(pattern)) pattern = 0; if (isNaN(pattern)) return format.call(this, pattern); pattern = Number(pattern); threshold = toPosInt(arguments[1]); if (pattern === 1) return this._toString1(threshold); return this._toStringDefault(threshold); }) }); duration-0.2.2/package.json000066400000000000000000000016641336635451700156520ustar00rootroot00000000000000{ "name": "duration", "version": "0.2.2", "description": "Time duration utilities", "author": "Mariusz Nowak (http://www.medikoo.com/)", "keywords": [ "date", "duration", "time" ], "repository": { "type": "git", "url": "git://github.com/medikoo/duration.git" }, "dependencies": { "d": "1", "es5-ext": "~0.10.46" }, "devDependencies": { "eslint": "^5.8", "eslint-config-medikoo-es5": "^1.7.2", "tad": "~0.2.8" }, "eslintConfig": { "extends": "medikoo-es5", "root": true, "rules": { "consistent-return": "off", "id-length": "off" }, "overrides": [ { "files": "test/**", "rules": { "max-lines": "off", "max-statements": "off" } } ] }, "scripts": { "lint": "eslint --ignore-path=.gitignore .", "test": "node ./node_modules/tad/bin/tad" }, "license": "ISC" } duration-0.2.2/test/000077500000000000000000000000001336635451700143345ustar00rootroot00000000000000duration-0.2.2/test/index.js000066400000000000000000000721321336635451700160060ustar00rootroot00000000000000"use strict"; var copy = require("es5-ext/date/#/copy"); module.exports = function (t) { var d1 = new Date(Date.UTC(2001, 1, 2, 1, 1, 1, 1)), d, d2; return { "Second date is optional": function (a) { var d3, m; d2 = new Date(); d = t(d1); d3 = new Date(); a.ok((m = d.milliseconds) >= t(d1, d2).milliseconds && m <= t(d1, d3).milliseconds); }, "Milliseconds": function (a) { // 11 milliseconds d2 = copy.call(d1); d2.setMilliseconds(d2.getMilliseconds() + 11); d = t(d1, d2); a(d.milliseconds, 11, "Milliseconds"); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, 0, "Seconds"); a(d.minutes, 0, "Minutes"); a(d.hours, 0, "Hours"); a(d.days, 0, "Days"); a(d.months, 0, "Months"); a(d.years, 0, "Years"); a(d.millisecond, 11, "Trailing milliseconds"); a(d.second, 0, "Trailing seconds"); a(d.minute, 0, "Trailing minutes"); a(d.hour, 0, "Trailing hours"); a(d.day, 0, "Trailing days"); a(d.month, 0, "Trailing months"); a(d.year, 0, "Trailing years"); a(d.toString(), ".011", "String presentation"); a(d.toString(0, 0), ".011", "String presentation: Threshold #0"); a(d.toString(0, 1), "0", "String presentation: Threshold #1"); a(d.toString(0, 2), "0", "String presentation: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Threshold #7"); a(d.toString(1), "11ms", "String presentation #2"); a(d.toString(1, 0), "11ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "0s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "0m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .011.11.00.0.00.0.00.0.00.0.00.0.0 ", "String presentation (custom)" ); d = t(d2, d1); a(d.milliseconds, -11, "Milliseconds: Negative"); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, 0, "Seconds: Negative"); a(d.minutes, 0, "Minutes: Negative"); a(d.hours, 0, "Hours: Negative"); a(d.days, 0, "Day: Negatives"); a(d.months, 0, "Months: Negative"); a(d.years, 0, "Years: Negative"); a(d.millisecond, -11, "Trailing milliseconds: Negative"); a(d.second, 0, "Trailing seconds: Negative"); a(d.minute, 0, "Trailing minutes: Negative"); a(d.hour, 0, "Trailing hours: Negative"); a(d.day, 0, "Trailing days: Negative"); a(d.month, 0, "Trailing months: Negative"); a(d.year, 0, "Trailing years: Negative"); a(d.toString(), "-.011", "String presentation: Negative"); a(d.toString(0, 0), "-.011", "String presentation: Negative: Threshold #0"); a(d.toString(0, 1), "0", "String presentation: Negative: Threshold #1"); a(d.toString(0, 2), "0", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Negative: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Negative: Threshold #7"); a(d.toString(1), "-11ms", "String presentation #2: Negative"); a(d.toString(1, 0), "-11ms", "String presentation #2: Negative: Threshold #0"); a(d.toString(1, 1), "0s", "String presentation #2: Negative: Threshold #1"); a(d.toString(1, 2), "0m", "String presentation #2: Negative: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.011.11.00.0.00.0.00.0.00.0.00.0.0 ", "String presentation (custom): Negative" ); }, "Seconds": function (a) { // 7 seconds 123 milliseconds d2 = copy.call(d1); d2.setMilliseconds(d2.getMilliseconds() + 123); d2.setSeconds(d2.getSeconds() + 7); d = t(d1, d2); a(d.milliseconds, 7 * 1000 + 123, "Milliseconds"); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, 7, "Seconds"); a(d.minutes, 0, "Minutes"); a(d.hours, 0, "Hours"); a(d.days, 0, "Days"); a(d.months, 0, "Months"); a(d.years, 0, "Years"); a(d.millisecond, 123, "Trailing milliseconds"); a(d.second, 7, "Trailing seconds"); a(d.minute, 0, "Trailing minutes"); a(d.hour, 0, "Trailing hours"); a(d.day, 0, "Trailing days"); a(d.month, 0, "Trailing months"); a(d.year, 0, "Trailing years"); a(d.toString(), "7.123", "String presentation"); a(d.toString(0, 0), "7.123", "String presentation: Threshold #0"); a(d.toString(0, 1), "7", "String presentation: Threshold #1"); a(d.toString(0, 2), "0", "String presentation: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Threshold #7"); a(d.toString(1), "7s 123ms", "String presentation #2"); a(d.toString(1, 0), "7s 123ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "7s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "0m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .123." + (7 * 1000 + 123) + ".07.7.00.0.00.0.00.0.00.0.0 ", "String presentation (custom)" ); d = t(d2, d1); a(d.milliseconds, -(7 * 1000 + 123), "Milliseconds: Negative"); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, -7, "Seconds: Negative"); a(d.minutes, 0, "Minutes: Negative"); a(d.hours, 0, "Hours: Negative"); a(d.days, 0, "Days: Negative"); a(d.months, 0, "Months: Negative"); a(d.years, 0, "Years: Negative"); a(d.millisecond, -123, "Trailing milliseconds: Negative"); a(d.second, -7, "Trailing seconds: Negative"); a(d.minute, 0, "Trailing minutes: Negative"); a(d.hour, 0, "Trailing hours: Negative"); a(d.day, 0, "Trailing days: Negative"); a(d.month, 0, "Trailing months: Negative"); a(d.year, 0, "Trailing years: Negative"); a(d.toString(), "-7.123", "String presentation: Negative"); a(d.toString(0, 0), "-7.123", "String presentation: Negative: Threshold #0"); a(d.toString(0, 1), "-7", "String presentation: Negative: Threshold #1"); a(d.toString(0, 2), "0", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Negative: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Negative: Threshold #7"); a(d.toString(1), "-7s 123ms", "String presentation #2: Negative"); a(d.toString(1, 0), "-7s 123ms", "String presentation #2: Negative: Threshold #0"); a(d.toString(1, 1), "-7s", "String presentation #2: Negative: Threshold #1"); a(d.toString(1, 2), "0m", "String presentation #2: Negative: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.123." + (7 * 1000 + 123) + ".07.7.00.0.00.0.00.0.00.0.0 ", "String presentation (custom): Negative" ); }, "Minutes": function (a) { // 7 minutes 12 seconds 123 milliseconds d2 = copy.call(d1); d2.setMilliseconds(d2.getMilliseconds() + 123); d2.setSeconds(d2.getSeconds() + 12); d2.setMinutes(d2.getMinutes() + 7); d = t(d1, d2); a(d.milliseconds, 7 * 60 * 1000 + 12 * 1000 + 123, "Milliseconds"); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, 7 * 60 + 12, "Seconds"); a(d.minutes, 7, "Minutes"); a(d.hours, 0, "Hours"); a(d.days, 0, "Days"); a(d.months, 0, "Months"); a(d.years, 0, "Years"); a(d.millisecond, 123, "Trailing milliseconds"); a(d.second, 12, "Trailing seconds"); a(d.minute, 7, "Trailing minutes"); a(d.hour, 0, "Trailing hours"); a(d.day, 0, "Trailing days"); a(d.month, 0, "Trailing months"); a(d.year, 0, "Trailing years"); a(d.toString(), "07:12.123", "String presentation"); a(d.toString(0, 0), "07:12.123", "String presentation: Threshold #0"); a(d.toString(0, 1), "07:12", "String presentation: Threshold #1"); a(d.toString(0, 2), "7", "String presentation: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Threshold #7"); a(d.toString(1), "7m 12s 123ms", "String presentation #2"); a(d.toString(1, 0), "7m 12s 123ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "7m 12s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "7m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .123." + (7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (7 * 60 + 12) + ".07.7.00.0.00.0.00.0.0 ", "String presentation (custom)" ); d = t(d2, d1); a(d.milliseconds, -(7 * 60 * 1000 + 12 * 1000 + 123), "Milliseconds: Negative"); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, -(7 * 60 + 12), "Seconds: Negative"); a(d.minutes, -7, "Minutes: Negative"); a(d.hours, 0, "Hours: Negative"); a(d.days, 0, "Days: Negative"); a(d.months, 0, "Months: Negative"); a(d.years, 0, "Years: Negative"); a(d.millisecond, -123, "Trailing milliseconds: Negative"); a(d.second, -12, "Trailing seconds: Negative"); a(d.minute, -7, "Trailing minutes: Negative"); a(d.hour, 0, "Trailing hours: Negative"); a(d.day, 0, "Trailing days: Negative"); a(d.month, 0, "Trailing months: Negative"); a(d.year, 0, "Trailing years: Negative"); a(d.toString(), "-07:12.123", "String presentation: Negative"); a(d.toString(0, 0), "-07:12.123", "String presentation: Negative: Threshold #0"); a(d.toString(0, 1), "-07:12", "String presentation: Negative: Threshold #1"); a(d.toString(0, 2), "-7", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "00", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Negative: Threshold #6"); a(d.toString(1), "-7m 12s 123ms", "String presentation #2: Negative"); a(d.toString(1, 0), "-7m 12s 123ms", "String presentation #2: Negative: Threshold #0"); a(d.toString(1, 1), "-7m 12s", "String presentation #2: Negative: Threshold #1"); a(d.toString(1, 2), "-7m", "String presentation #2: Negative: Threshold #2"); a(d.toString(1, 3), "0h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.123." + (7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (7 * 60 + 12) + ".07.7.00.0.00.0.00.0.0 ", "String presentation (custom): Negative" ); }, "Hours": function (a) { // 4 hours 7 minutes 12 seconds 123 milliseconds d2 = copy.call(d1); d2.setMilliseconds(d2.getMilliseconds() + 123); d2.setSeconds(d2.getSeconds() + 12); d2.setMinutes(d2.getMinutes() + 7); d2.setHours(d2.getHours() + 4); d = t(d1, d2); a(d.milliseconds, 4 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123, "Milliseconds"); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, 4 * 60 * 60 + 7 * 60 + 12, "Seconds"); a(d.minutes, 4 * 60 + 7, "Minutes"); a(d.hours, 4, "Hours"); a(d.days, 0, "Days"); a(d.months, 0, "Months"); a(d.years, 0, "Years"); a(d.millisecond, 123, "Trailing milliseconds"); a(d.second, 12, "Trailing seconds"); a(d.minute, 7, "Trailing minutes"); a(d.hour, 4, "Trailing hours"); a(d.day, 0, "Trailing days"); a(d.month, 0, "Trailing months"); a(d.year, 0, "Trailing years"); a(d.toString(), "04:07:12.123", "String presentation"); a(d.toString(0, 0), "04:07:12.123", "String presentation: Threshold #0"); a(d.toString(0, 1), "04:07:12", "String presentation: Threshold #1"); a(d.toString(0, 2), "04:07", "String presentation: Threshold #2"); a(d.toString(0, 3), "04", "String presentation: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Threshold #7"); a(d.toString(1), "4h 7m 12s 123ms", "String presentation #2"); a(d.toString(1, 0), "4h 7m 12s 123ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "4h 7m 12s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "4h 7m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "4h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .123." + (4 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (4 * 60 * 60 + 7 * 60 + 12) + ".07." + (4 * 60 + 7) + ".04.4.00.0.00.0.0 ", "String presentation (custom)" ); d = t(d2, d1); a( d.milliseconds, -(4 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123), "Milliseconds: Negative" ); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, -(4 * 60 * 60 + 7 * 60 + 12), "Seconds: Negative"); a(d.minutes, -(4 * 60 + 7), "Minutes: Negative"); a(d.hours, -4, "Hours: Negative"); a(d.days, 0, "Days: Negative"); a(d.months, 0, "Months: Negative"); a(d.years, 0, "Years: Negative"); a(d.millisecond, -123, "Trailing milliseconds: Negative"); a(d.second, -12, "Trailing seconds: Negative"); a(d.minute, -7, "Trailing minutes: Negative"); a(d.hour, -4, "Trailing hours: Negative"); a(d.day, 0, "Trailing days: Negative"); a(d.month, 0, "Trailing months: Negative"); a(d.year, 0, "Trailing years: Negative"); a(d.toString(), "-04:07:12.123", "String presentation: Negative"); a(d.toString(0, 0), "-04:07:12.123", "String presentation: Negative: Threshold #0"); a(d.toString(0, 1), "-04:07:12", "String presentation: Negative: Threshold #1"); a(d.toString(0, 2), "-04:07", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "-04", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "0d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Negative: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Negative: Threshold #7"); a(d.toString(1), "-4h 7m 12s 123ms", "String presentation #2: Negative"); a( d.toString(1, 0), "-4h 7m 12s 123ms", "String presentation #2: Negative: Threshold #0" ); a(d.toString(1, 1), "-4h 7m 12s", "String presentation #2: Negative: Threshold #1"); a(d.toString(1, 2), "-4h 7m", "String presentation #2: Negative: Threshold #2"); a(d.toString(1, 3), "-4h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "0d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.123." + (4 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (4 * 60 * 60 + 7 * 60 + 12) + ".07." + (4 * 60 + 7) + ".04.4.00.0.00.0.0 ", "String presentation (custom): Negative" ); }, "Days": function (a) { // 2 days 14 hours 7 minutes 12 seconds 123 milliseconds d2 = copy.call(d1); d2.setMilliseconds(d2.getMilliseconds() + 123); d2.setSeconds(d2.getSeconds() + 12); d2.setMinutes(d2.getMinutes() + 7); d2.setHours(d2.getHours() + 14); d2.setDate(d2.getDate() + 2); d = t(d1, d2); a( d.milliseconds, 2 * 24 * 60 * 60 * 1000 + 14 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123, "Milliseconds" ); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, 2 * 24 * 60 * 60 + 14 * 60 * 60 + 7 * 60 + 12, "Seconds"); a(d.minutes, 2 * 24 * 60 + 14 * 60 + 7, "Minutes"); a(d.hours, 2 * 24 + 14, "Hours"); a(d.days, 2, "Days"); a(d.months, 0, "Months"); a(d.years, 0, "Years"); a(d.millisecond, 123, "Trailing milliseconds"); a(d.second, 12, "Trailing seconds"); a(d.minute, 7, "Trailing minutes"); a(d.hour, 14, "Trailing hours"); a(d.day, 2, "Trailing days"); a(d.month, 0, "Trailing months"); a(d.year, 0, "Trailing years"); a(d.toString(), "2d 14:07:12.123", "String presentation"); a(d.toString(0, 0), "2d 14:07:12.123", "String presentation: Threshold #0"); a(d.toString(0, 1), "2d 14:07:12", "String presentation: Threshold #1"); a(d.toString(0, 2), "2d 14:07", "String presentation: Threshold #2"); a(d.toString(0, 3), "2d 14", "String presentation: Threshold #3"); a(d.toString(0, 4), "2d", "String presentation: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Threshold #7"); a(d.toString(1), "2d 14h 7m 12s 123ms", "String presentation #2"); a(d.toString(1, 0), "2d 14h 7m 12s 123ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "2d 14h 7m 12s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "2d 14h 7m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "2d 14h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "2d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .123." + (2 * 24 * 60 * 60 * 1000 + 14 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (2 * 24 * 60 * 60 + 14 * 60 * 60 + 7 * 60 + 12) + ".07." + (2 * 24 * 60 + 14 * 60 + 7) + ".14." + (2 * 24 + 14) + ".02.2.00.0.0 ", "String presentation (custom)" ); d = t(d2, d1); a( d.milliseconds, -(2 * 24 * 60 * 60 * 1000 + 14 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123), "Milliseconds: Negative" ); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, -(2 * 24 * 60 * 60 + 14 * 60 * 60 + 7 * 60 + 12), "Seconds: Negative"); a(d.minutes, -(2 * 24 * 60 + 14 * 60 + 7), "Minutes: Negative"); a(d.hours, -(2 * 24 + 14), "Hours: Negative"); a(d.days, -2, "Days: Negative"); a(d.months, 0, "Months: Negative"); a(d.years, 0, "Years: Negative"); a(d.millisecond, -123, "Trailing milliseconds: Negative"); a(d.second, -12, "Trailing seconds: Negative"); a(d.minute, -7, "Trailing minutes: Negative"); a(d.hour, -14, "Trailing hours: Negative"); a(d.day, -2, "Trailing days: Negative"); a(d.month, 0, "Trailing months: Negative"); a(d.year, 0, "Trailing years: Negative"); a(d.toString(), "-2d 14:07:12.123", "String presentation: Negative"); a(d.toString(0, 0), "-2d 14:07:12.123", "String presentation: Negative: Threshold #0"); a(d.toString(0, 1), "-2d 14:07:12", "String presentation: Negative: Threshold #1"); a(d.toString(0, 2), "-2d 14:07", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "-2d 14", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "-2d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "0m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "0y", "String presentation: Negative: Threshold #6"); a(d.toString(0, 7), "0y", "String presentation: Negative: Threshold #7"); a(d.toString(1), "-2d 14h 7m 12s 123ms", "String presentation #2: Negative"); a( d.toString(1, 0), "-2d 14h 7m 12s 123ms", "String presentation #2: Negative: Threshold #0" ); a(d.toString(1, 1), "-2d 14h 7m 12s", "String presentation #2: Negative: Threshold #1"); a(d.toString(1, 2), "-2d 14h 7m", "String presentation #2: Negative: Threshold #2"); a(d.toString(1, 3), "-2d 14h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "-2d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "0m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "0y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "0y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.123." + (2 * 24 * 60 * 60 * 1000 + 14 * 60 * 60 * 1000 + 7 * 60 * 1000 + 12 * 1000 + 123) + ".12." + (2 * 24 * 60 * 60 + 14 * 60 * 60 + 7 * 60 + 12) + ".07." + (2 * 24 * 60 + 14 * 60 + 7) + ".14." + (2 * 24 + 14) + ".02.2.00.0.0 ", "String presentation (custom): Negative" ); }, "Large duration": function (a) { // Few years, few months var days = 365 * 2 + 28 + 31; d2 = new Date(Date.UTC(2003, 3, 2, 1, 1, 1, 1)); d = t(d1, d2); a(d.milliseconds, days * 24 * 60 * 60 * 1000, "Milliseconds"); a(d.valueOf(), d.milliseconds, "Value"); a(d.seconds, days * 24 * 60 * 60, "Seconds"); a(d.minutes, days * 24 * 60, "Minutes"); a(d.hours, days * 24, "Hours"); a(d.days, days, "Days"); a(d.months, 26, "Months"); a(d.years, 2, "Years"); a(d.millisecond, 0, "Trailing milliseconds"); a(d.second, 0, "Trailing seconds"); a(d.minute, 0, "Trailing minutes"); a(d.hour, 0, "Trailing hours"); a(d.day, 0, "Trailing days"); a(d.month, 2, "Trailing months"); a(d.year, 2, "Trailing years"); a(d.toString(), "2y 2m 0d 00:00:00.000", "String presentation"); a(d.toString(0, 0), "2y 2m 0d 00:00:00.000", "String presentation: Threshold #0"); a(d.toString(0, 1), "2y 2m 0d 00:00:00", "String presentation: Threshold #1"); a(d.toString(0, 2), "2y 2m 0d 00:00", "String presentation: Threshold #2"); a(d.toString(0, 3), "2y 2m 0d 00", "String presentation: Threshold #3"); a(d.toString(0, 4), "2y 2m 0d", "String presentation: Threshold #4"); a(d.toString(0, 5), "2y 2m", "String presentation: Threshold #5"); a(d.toString(0, 6), "2y", "String presentation: Threshold #6"); a(d.toString(0, 7), "2y", "String presentation: Threshold #7"); a(d.toString(1), "2y 2m 0d 0h 0m 0s 0ms", "String presentation #2"); a(d.toString(1, 0), "2y 2m 0d 0h 0m 0s 0ms", "String presentation #2: Threshold #0"); a(d.toString(1, 1), "2y 2m 0d 0h 0m 0s", "String presentation #2: Threshold #1"); a(d.toString(1, 2), "2y 2m 0d 0h 0m", "String presentation #2: Threshold #2"); a(d.toString(1, 3), "2y 2m 0d 0h", "String presentation #2: Threshold #3"); a(d.toString(1, 4), "2y 2m 0d", "String presentation #2: Threshold #4"); a(d.toString(1, 5), "2y 2m", "String presentation #2: Threshold #5"); a(d.toString(1, 6), "2y", "String presentation #2: Threshold #6"); a(d.toString(1, 7), "2y", "String presentation #2: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " .000." + days * 24 * 60 * 60 * 1000 + ".00." + days * 24 * 60 * 60 + ".00." + days * 24 * 60 + ".00." + days * 24 + ".00." + days + ".02." + 26 + ".2 ", "String presentation (custom)" ); d = t(d2, d1); a(d.milliseconds, -(days * 24 * 60 * 60 * 1000), "Milliseconds: Negative"); a(d.valueOf(), d.milliseconds, "Value: Negative"); a(d.seconds, -(days * 24 * 60 * 60), "Seconds: Negative"); a(d.minutes, -(days * 24 * 60), "Minutes: Negative"); a(d.hours, -(days * 24), "Hours: Negative"); a(d.days, -days, "Days: Negative"); a(d.months, -26, "Months: Negative"); a(d.years, -2, "Years: Negative"); a(d.millisecond, 0, "Trailing milliseconds: Negative"); a(d.second, 0, "Trailing seconds: Negative"); a(d.minute, 0, "Trailing minutes: Negative"); a(d.hour, 0, "Trailing hours: Negative"); a(d.day, 0, "Trailing days: Negative"); a(d.month, -2, "Trailing months: Negative"); a(d.year, -2, "Trailing years: Negative"); a(d.toString(), "-2y 2m 0d 00:00:00.000", "String presentation: Negative"); a( d.toString(0, 0), "-2y 2m 0d 00:00:00.000", "String presentation: Negative: Threshold #0" ); a( d.toString(0, 1), "-2y 2m 0d 00:00:00", "String presentation: Negative: Threshold #1" ); a(d.toString(0, 2), "-2y 2m 0d 00:00", "String presentation: Negative: Threshold #2"); a(d.toString(0, 3), "-2y 2m 0d 00", "String presentation: Negative: Threshold #3"); a(d.toString(0, 4), "-2y 2m 0d", "String presentation: Negative: Threshold #4"); a(d.toString(0, 5), "-2y 2m", "String presentation: Negative: Threshold #5"); a(d.toString(0, 6), "-2y", "String presentation: Negative: Threshold #6"); a(d.toString(0, 7), "-2y", "String presentation: Negative: Threshold #7"); a(d.toString(1), "-2y 2m 0d 0h 0m 0s 0ms", "String presentation #2: Negative"); a( d.toString(1, 0), "-2y 2m 0d 0h 0m 0s 0ms", "String presentation #2: Negative: Threshold #0" ); a( d.toString(1, 1), "-2y 2m 0d 0h 0m 0s", "String presentation #2: Negative: Threshold #1" ); a( d.toString(1, 2), "-2y 2m 0d 0h 0m", "String presentation #2: Negative: Threshold #2" ); a(d.toString(1, 3), "-2y 2m 0d 0h", "String presentation #2: Negative: Threshold #3"); a(d.toString(1, 4), "-2y 2m 0d", "String presentation #2: Negative: Threshold #4"); a(d.toString(1, 5), "-2y 2m", "String presentation #2: Negative: Threshold #5"); a(d.toString(1, 6), "-2y", "String presentation #2: Negative: Threshold #6"); a(d.toString(1, 7), "-2y", "String presentation #2: Negative: Threshold #7"); a( d.toString(" %sign.%L.%Ls.%S.%Ss.%M.%Ms.%H.%Hs.%d.%ds.%m.%ms.%y "), " -.000." + days * 24 * 60 * 60 * 1000 + ".00." + days * 24 * 60 * 60 + ".00." + days * 24 * 60 + ".00." + days * 24 + ".00." + days + ".02." + 26 + ".2 ", "String presentation (custom): Negative" ); }, "Special case": function (t, a) { var dateFrom = new Date(1540999566129); var dateTo = new Date(1577750400000); d = t(dateFrom, dateTo); a(d.day, 30); } }; };