New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

duratiform

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duratiform - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

.huskyrc.json

14

bower.json
{
"name": "duratiform",
"main": [
"dist/duratiform.js",
"dist/duratiform.js",
"dist/duratiform.min.js"
],
"version": "1.0.0",
"version": "2.0.0",
"homepage": "https://github.com/gamtiq/duratiform",

@@ -16,9 +16,17 @@ "authors": [

"duration",
"period",
"interval",
"span",
"divide",
"separate",
"decompose",
"parse",
"part",
"partition",
"format",
"string",
"stringify",
"millisecond"
"millisecond",
"milliseconds",
"ms"
],

@@ -25,0 +33,0 @@ "license": "MIT",

@@ -5,13 +5,21 @@ {

"description": "Utility to separate into parts and to format time duration in milliseconds",
"version": "1.0.0",
"version": "2.0.0",
"keywords": [
"time",
"duration",
"period",
"interval",
"span",
"divide",
"separate",
"decompose",
"parse",
"part",
"partition",
"format",
"string",
"stringify",
"millisecond"
"millisecond",
"milliseconds",
"ms"
],

@@ -25,2 +33,2 @@ "dependencies": {},

]
}
}

@@ -17,3 +17,3 @@ (function(root, factory) {

/**
* @module duratiform
* @module duratiform
*/

@@ -23,3 +23,3 @@

* Separate time duration into parts.
*
*
* @param {Integer} nDuration

@@ -35,6 +35,7 @@ * Time duration in milliseconds.

* <li><code>4</code> - return quantity of days, hours, minutes and seconds (<code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> fields)
* <li><code>5</code> - return quantity of weeks, days, hours, minutes and seconds (<code>week</code>, <code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> fields)
* </ul>
* @param {Boolean} [bAddStrings]
* Specifies whether additional string fields should be included into result object.
* An additional field represents a value of calculated part that is converted into string
* An additional field represents a value of calculated part that is converted into string
* and is prefixed with "0" if it is necessary (i.e. values from 0 to 9 are converted to "00"-"09").

@@ -59,3 +60,3 @@ * The default value is <code>false</code>.

* <td>
* Quantity of full days. String contains at least 2 characters.
* Quantity of full days. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -73,3 +74,3 @@ * </td>

* <td>
* Quantity of full hours. String contains at least 2 characters.
* Quantity of full hours. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -87,3 +88,3 @@ * </td>

* <td>
* Quantity of full minutes. String contains at least 2 characters.
* Quantity of full minutes. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -101,6 +102,19 @@ * </td>

* <td>
* Quantity of full seconds. String contains at least 2 characters.
* Quantity of full seconds. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.
* </td>
* </tr>
* <tr>
* <td>week</td>
* <td>Integer</td>
* <td>Quantity of full weeks</td>
* </tr>
* <tr>
* <td>week2</td>
* <td>String</td>
* <td>
* Quantity of full weeks. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.
* </td>
* </tr>
* </table>

@@ -111,3 +125,3 @@ * @alias module:duratiform.divide

var result = {};
function getPart(sField, nDivisor) {

@@ -126,3 +140,3 @@ var nV;

}
// Convert duration to seconds

@@ -133,3 +147,7 @@ nDuration = nDuration * 0.001;

}
// Extract weeks
if (nPartQty > 4) {
getPart("week", 604800);
}
// Extract days

@@ -156,3 +174,3 @@ if (nPartQty > 3) {

* Convert time duration into string.
*
*
* @param {Integer} nDuration

@@ -173,2 +191,4 @@ * Time duration in milliseconds.

* <li><code>ss</code> - quantity of seconds (2 or more characters)
* <li><code>w</code> - quantity of weeks (1 or more characters)
* <li><code>ww</code> - quantity of weeks (2 or more characters)
* <li><code>[</code> - cancel special processing of the following characters (except <code>\x</code> and <code>]</code>);

@@ -180,5 +200,10 @@ * this character won't be included into the result

* will be included into the result as is but without brackets
* <li><code>(x:</code> - where <code>x</code> is one of <code>d</code> (days), <code>h</code> (hours),
* <code>m</code> (minutes) or <code>s</code> (seconds), begin group of characters
* that will be included in the result only when the corresponding part of duration is present (above 0)
* <li><code>(x:</code> - where <code>x</code> is one of <code>w</code> (weeks), <code>d</code> (days),
* <code>h</code> (hours), <code>m</code> (minutes) or <code>s</code> (seconds),
* begin group of characters that will be included in the result
* only when the corresponding part of duration is present (above 0)
* <li><code>(!x:</code> - where <code>x</code> is one of <code>w</code> (weeks), <code>d</code> (days),
* <code>h</code> (hours), <code>m</code> (minutes) or <code>s</code> (seconds),
* begin group of characters that will be included in the result
* only when the corresponding part of duration is not present (equals to 0)
* <li><code>)</code> - end of previous group; thus by using format <code>(h:h:)mm:ss</code> hours part

@@ -200,2 +225,3 @@ * will be in result only when duration is greater than 60 minutes

specialChar = {
w: ["week", 5],
d: ["day", 4],

@@ -207,7 +233,25 @@ h: ["hour", 3],

sSlash = "\\",
nI, nK, nL, sChar, part, struct;
bNegative, nI, nK, nL, sChar, sNextChar, part, struct;
function getGroupList() {
return group && groupList.concat(group);
}
function getPart() {
var group = this.g;
return ! group || struct[group]
var groupSet = this.g,
bNot, nEnd, nNum, sGroupExpr;
if (groupSet) {
for (nNum = 0, nEnd = groupSet.length; nNum < nEnd; nNum++) {
sGroupExpr = groupSet[nNum];
bNot = sGroupExpr.charAt(0) === "!";
if ((bNot && struct[sGroupExpr.substring(1)]) || (! bNot && ! struct[sGroupExpr])) {
groupSet = false;
break;
}
}
}
else {
groupSet = true;
}
return groupSet
? this.c || String(struct[this.p])

@@ -223,2 +267,3 @@ : "";

sChar = sFormat.charAt(nI);
sNextChar = sFormat.charAt(nI + 1);
// Special character

@@ -229,3 +274,3 @@ if (bReplace && sChar in specialChar) {

// 2 or more characters
if (sFormat.charAt(nI + 1) === sChar) {
if (sNextChar === sChar) {
part = struct[0] + "2";

@@ -238,3 +283,3 @@ nI++;

}
result.push({p: part, g: group, toString: getPart});
result.push({p: part, g: getGroupList(), toString: getPart});
// Change quantity of time duration parts if it is necessary

@@ -254,9 +299,11 @@ if (struct[1] > nP) {

// Start of a group
else if (bReplace && sChar === "(" && sFormat.charAt(nI + 2) === ":"
&& (part = sFormat.charAt(nI + 1).match(/d|h|m|s/))) {
else if (bReplace && sChar === "("
&& ((bNegative = sNextChar === "!") || true)
&& sFormat.charAt(nI + (bNegative ? 3 : 2)) === ":"
&& (part = (bNegative ? sFormat.charAt(nI + 2) : sNextChar).match(/d|h|m|s|w/))) {
if (group) {
groupList.push(group);
}
group = specialChar[part[0]][0];
nI += 2;
group = (bNegative ? "!" : "") + specialChar[part[0]][0];
nI += bNegative ? 3 : 2;
}

@@ -273,7 +320,8 @@ // End of a group

if (sChar === sSlash) {
sChar = sFormat.charAt(++nI);
sChar = sNextChar;
nI++;
}
result.push(
group
? {g: group, c: sChar, toString: getPart}
? {g: getGroupList(), c: sChar, toString: getPart}
: sChar

@@ -280,0 +328,0 @@ );

@@ -1,1 +0,1 @@

!function(r,t){if(void 0===r&&void 0!==window&&(r=window),"object"==typeof module&&module.exports)module.exports=t(require,exports,module);else if("function"==typeof define&&define.amd)define(["require","exports","module"],t);else{var e=r,n={exports:e};r.duratiform=t(function(t){return r[t]},e,n)}}(this,function(t,r,e){function l(n,t,o){var i={};function r(t,r){var e;r<=n?(e=i[t]=Math.floor(n/r),n%=r):e=i[t]=0,o&&(i[t+"2"]=e<10?"0"+e:String(e))}return n*=.001,t||(t=3),3<t&&r("day",86400),2<t&&r("hour",3600),1<t&&r("minute",60),0<t&&r("second",1),i}return e.exports={divide:l,format:function(t,r){var e,n,o,i,u,d,h=[],s=!0,c=null,f=[],a=0,p={d:["day",4],h:["hour",3],m:["minute",2],s:["second",1]};function m(){var t=this.g;return!t||d[t]?this.c||String(d[this.p]):""}for(r||(r="hh:mm:ss"),e=0,n=(o=r.length)-1;e<o;e++)i=r.charAt(e),s&&i in p?(d=p[i],r.charAt(e+1)===i?(u=d[0]+"2",e++):u=d[0],h.push({p:u,g:c,toString:m}),d[1]>a&&(a=d[1])):s&&"["===i?s=!1:s||"]"!==i?s&&"("===i&&":"===r.charAt(e+2)&&(u=r.charAt(e+1).match(/d|h|m|s/))?(c&&f.push(c),c=p[u[0]][0],e+=2):s&&c&&")"===i?c=f.length?f.pop():null:("\\"!==i||e<n)&&("\\"===i&&(i=r.charAt(++e)),h.push(c?{g:c,c:i,toString:m}:i)):s=!0;return a&&(d=l(t,a,!0)),h.join("")}},e.exports});
!function(e,t){if(void 0===e&&void 0!==window&&(e=window),"object"==typeof module&&module.exports)module.exports=t(require,exports,module);else if("function"==typeof define&&define.amd)define(["require","exports","module"],t);else{var r={exports:e};e.duratiform=t(0,0,r)}}(this,function(e,t,r){function w(n,e,o){var i={};function t(e,t){var r;t<=n?(r=i[e]=Math.floor(n/t),n%=t):r=i[e]=0,o&&(i[e+"2"]=r<10?"0"+r:String(r))}return n*=.001,4<(e=e||3)&&t("week",604800),3<e&&t("day",86400),2<e&&t("hour",3600),1<e&&t("minute",60),0<e&&t("second",1),i}return r.exports={divide:w,format:function(e,t){var r,n,o,i,u,s,h,d,f=[],c=!0,a=null,l=[],p=0,m={w:["week",5],d:["day",4],h:["hour",3],m:["minute",2],s:["second",1]};function g(){return a&&l.concat(a)}function v(){var e,t,r,n,o=this.g;if(o){for(r=0,t=o.length;r<t;r++)if((e="!"===(n=o[r]).charAt(0))&&d[n.substring(1)]||!e&&!d[n]){o=!1;break}}else o=!0;return o?this.c||String(d[this.p]):""}for(n=0,o=(i=(t=t||"hh:mm:ss").length)-1;n<i;n++)u=t.charAt(n),s=t.charAt(n+1),c&&u in m?(d=m[u],s===u?(h=d[0]+"2",n++):h=d[0],f.push({p:h,g:g(),toString:v}),d[1]>p&&(p=d[1])):c&&"["===u?c=!1:c||"]"!==u?c&&"("===u&&(r="!"===s,1)&&":"===t.charAt(n+(r?3:2))&&(h=(r?t.charAt(n+2):s).match(/d|h|m|s|w/))?(a&&l.push(a),a=(r?"!":"")+m[h[0]][0],n+=r?3:2):c&&a&&")"===u?a=l.length?l.pop():null:("\\"!==u||n<o)&&("\\"===u&&(u=s,n++),f.push(a?{g:g(),c:u,toString:v}:u)):c=!0;return p&&(d=w(e,p,!0)),f.join("")}},r.exports});
/**
* @module duratiform
* @module duratiform
*/

@@ -7,3 +7,3 @@

* Separate time duration into parts.
*
*
* @param {Integer} nDuration

@@ -19,6 +19,7 @@ * Time duration in milliseconds.

* <li><code>4</code> - return quantity of days, hours, minutes and seconds (<code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> fields)
* <li><code>5</code> - return quantity of weeks, days, hours, minutes and seconds (<code>week</code>, <code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> fields)
* </ul>
* @param {Boolean} [bAddStrings]
* Specifies whether additional string fields should be included into result object.
* An additional field represents a value of calculated part that is converted into string
* An additional field represents a value of calculated part that is converted into string
* and is prefixed with "0" if it is necessary (i.e. values from 0 to 9 are converted to "00"-"09").

@@ -43,3 +44,3 @@ * The default value is <code>false</code>.

* <td>
* Quantity of full days. String contains at least 2 characters.
* Quantity of full days. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -57,3 +58,3 @@ * </td>

* <td>
* Quantity of full hours. String contains at least 2 characters.
* Quantity of full hours. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -71,3 +72,3 @@ * </td>

* <td>
* Quantity of full minutes. String contains at least 2 characters.
* Quantity of full minutes. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.

@@ -85,6 +86,19 @@ * </td>

* <td>
* Quantity of full seconds. String contains at least 2 characters.
* Quantity of full seconds. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.
* </td>
* </tr>
* <tr>
* <td>week</td>
* <td>Integer</td>
* <td>Quantity of full weeks</td>
* </tr>
* <tr>
* <td>week2</td>
* <td>String</td>
* <td>
* Quantity of full weeks. String contains at least 2 characters.
* This field is included only when <code>bAddStrings</code> has <code>true</code> value.
* </td>
* </tr>
* </table>

@@ -95,3 +109,3 @@ * @alias module:duratiform.divide

var result = {};
function getPart(sField, nDivisor) {

@@ -110,3 +124,3 @@ var nV;

}
// Convert duration to seconds

@@ -117,3 +131,7 @@ nDuration = nDuration * 0.001;

}
// Extract weeks
if (nPartQty > 4) {
getPart("week", 604800);
}
// Extract days

@@ -140,3 +158,3 @@ if (nPartQty > 3) {

* Convert time duration into string.
*
*
* @param {Integer} nDuration

@@ -157,2 +175,4 @@ * Time duration in milliseconds.

* <li><code>ss</code> - quantity of seconds (2 or more characters)
* <li><code>w</code> - quantity of weeks (1 or more characters)
* <li><code>ww</code> - quantity of weeks (2 or more characters)
* <li><code>[</code> - cancel special processing of the following characters (except <code>\x</code> and <code>]</code>);

@@ -164,5 +184,10 @@ * this character won't be included into the result

* will be included into the result as is but without brackets
* <li><code>(x:</code> - where <code>x</code> is one of <code>d</code> (days), <code>h</code> (hours),
* <code>m</code> (minutes) or <code>s</code> (seconds), begin group of characters
* that will be included in the result only when the corresponding part of duration is present (above 0)
* <li><code>(x:</code> - where <code>x</code> is one of <code>w</code> (weeks), <code>d</code> (days),
* <code>h</code> (hours), <code>m</code> (minutes) or <code>s</code> (seconds),
* begin group of characters that will be included in the result
* only when the corresponding part of duration is present (above 0)
* <li><code>(!x:</code> - where <code>x</code> is one of <code>w</code> (weeks), <code>d</code> (days),
* <code>h</code> (hours), <code>m</code> (minutes) or <code>s</code> (seconds),
* begin group of characters that will be included in the result
* only when the corresponding part of duration is not present (equals to 0)
* <li><code>)</code> - end of previous group; thus by using format <code>(h:h:)mm:ss</code> hours part

@@ -184,2 +209,3 @@ * will be in result only when duration is greater than 60 minutes

specialChar = {
w: ["week", 5],
d: ["day", 4],

@@ -191,7 +217,25 @@ h: ["hour", 3],

sSlash = "\\",
nI, nK, nL, sChar, part, struct;
bNegative, nI, nK, nL, sChar, sNextChar, part, struct;
function getGroupList() {
return group && groupList.concat(group);
}
function getPart() {
var group = this.g;
return ! group || struct[group]
var groupSet = this.g,
bNot, nEnd, nNum, sGroupExpr;
if (groupSet) {
for (nNum = 0, nEnd = groupSet.length; nNum < nEnd; nNum++) {
sGroupExpr = groupSet[nNum];
bNot = sGroupExpr.charAt(0) === "!";
if ((bNot && struct[sGroupExpr.substring(1)]) || (! bNot && ! struct[sGroupExpr])) {
groupSet = false;
break;
}
}
}
else {
groupSet = true;
}
return groupSet
? this.c || String(struct[this.p])

@@ -207,2 +251,3 @@ : "";

sChar = sFormat.charAt(nI);
sNextChar = sFormat.charAt(nI + 1);
// Special character

@@ -213,3 +258,3 @@ if (bReplace && sChar in specialChar) {

// 2 or more characters
if (sFormat.charAt(nI + 1) === sChar) {
if (sNextChar === sChar) {
part = struct[0] + "2";

@@ -222,3 +267,3 @@ nI++;

}
result.push({p: part, g: group, toString: getPart});
result.push({p: part, g: getGroupList(), toString: getPart});
// Change quantity of time duration parts if it is necessary

@@ -238,9 +283,11 @@ if (struct[1] > nP) {

// Start of a group
else if (bReplace && sChar === "(" && sFormat.charAt(nI + 2) === ":"
&& (part = sFormat.charAt(nI + 1).match(/d|h|m|s/))) {
else if (bReplace && sChar === "("
&& ((bNegative = sNextChar === "!") || true)
&& sFormat.charAt(nI + (bNegative ? 3 : 2)) === ":"
&& (part = (bNegative ? sFormat.charAt(nI + 2) : sNextChar).match(/d|h|m|s|w/))) {
if (group) {
groupList.push(group);
}
group = specialChar[part[0]][0];
nI += 2;
group = (bNegative ? "!" : "") + specialChar[part[0]][0];
nI += bNegative ? 3 : 2;
}

@@ -257,7 +304,8 @@ // End of a group

if (sChar === sSlash) {
sChar = sFormat.charAt(++nI);
sChar = sNextChar;
nI++;
}
result.push(
group
? {g: group, c: sChar, toString: getPart}
? {g: getGroupList(), c: sChar, toString: getPart}
: sChar

@@ -264,0 +312,0 @@ );

module.exports = function(grunt) {
// Configuration
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
name: "<%= pkg.name %>",

@@ -12,6 +12,6 @@ destName: "dist/<%= name %>",

src: "<%= name %>.js",
jshint: {
files: ["*.js", "test/*.js"],
options: {

@@ -32,3 +32,3 @@ // Enforcing

unused: true,
// Environment

@@ -38,18 +38,15 @@ node: true

},
jsdoc: {
dist: {
src: ["<%= src %>"],
options: {
destination: "doc",
template: "node_modules/ink-docstrap/template",
configure: "jsdoc-conf.json"
configure: "jsdoc-conf.js"
}
}
},
mochacli: {
all: {}
},
uglify: {

@@ -61,3 +58,3 @@ minify: {

},
umd: {

@@ -72,7 +69,19 @@ dist: {

}
},
bump: {
options: {
files: ["package.json", "package-lock.json", "bower.json", "component.json"],
commitMessage: "Release version %VERSION%",
commitFiles: ["-a"],
tagName: "%VERSION%",
tagMessage: "Version %VERSION%",
pushTo: "origin"
}
}
});
// Plugins
grunt.loadNpmTasks("grunt-bump");
grunt.loadNpmTasks("grunt-contrib-jshint");

@@ -83,3 +92,3 @@ grunt.loadNpmTasks("grunt-contrib-uglify");

grunt.loadNpmTasks("grunt-umd");
// Tasks

@@ -91,2 +100,6 @@ grunt.registerTask("build", ["umd", "uglify"]);

grunt.registerTask("all", ["default", "build", "doc"]);
grunt.registerTask("release", ["bump"]);
grunt.registerTask("release-minor", ["bump:minor"]);
grunt.registerTask("release-major", ["bump:major"]);
};

@@ -0,4 +1,10 @@

### 2.0.0 / 2020-05-04
* Add support for negative groups in `format` function.
* Add support for processing of nested groups in `format` function.
* Support of weeks.
### 1.0.0 / 2018-12-22
* Add support for conditional groups in format function.
* Add support for conditional groups in `format` function.
* Add types declaration file.

@@ -5,0 +11,0 @@ * Remove JAM and SPM support.

@@ -14,2 +14,4 @@ // Created on the basis of http://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html

second2?: string;
week?: number;
week2?: string;
}

@@ -16,0 +18,0 @@

{
"name": "duratiform",
"version": "1.0.0",
"version": "2.0.0",
"description": "Utility to separate into parts and to format time duration in milliseconds",

@@ -17,9 +17,17 @@ "main": "duratiform.js",

"duration",
"period",
"interval",
"span",
"divide",
"separate",
"decompose",
"parse",
"part",
"partition",
"format",
"string",
"stringify",
"millisecond"
"millisecond",
"milliseconds",
"ms"
],

@@ -33,10 +41,13 @@ "author": "Denis Sikuler",

"devDependencies": {
"grunt": "1.0.3",
"grunt-contrib-jshint": "2.0.0",
"grunt-contrib-uglify": "4.0.0",
"grunt-jsdoc": "2.3.0",
"grunt-mocha-cli": "4.0.0",
"docdash": "1.2.0",
"grunt": "1.1.0",
"grunt-bump": "0.8.0",
"grunt-contrib-jshint": "2.1.0",
"grunt-contrib-uglify": "4.0.1",
"grunt-jsdoc": "2.4.1",
"grunt-mocha-cli": "6.0.0",
"grunt-umd": "3.0.0",
"ink-docstrap": "1.3.2"
"husky": "4.2.5",
"jsdoc-file": "1.0.0"
}
}

@@ -5,2 +5,9 @@ # duratiform

```js
duratiform.divide(123456789000, 4); // { day: 1428, hour: 21, minute: 33, second: 9 }
duratiform.format(456789, '(h:h:)(m:mm:)(s:ss)'); // 07:36
```
[See additional examples below.](#examples)
[![NPM version](https://badge.fury.io/js/duratiform.png)](http://badge.fury.io/js/duratiform)

@@ -15,3 +22,3 @@ [![Build Status](https://travis-ci.org/gamtiq/duratiform.png)](https://travis-ci.org/gamtiq/duratiform)

### [Bower](http://bower.io)
### [Bower](https://bower.io)

@@ -29,3 +36,3 @@ bower install duratiform

```js
var duratiform = require("duratiform");
var duratiform = require('duratiform');
```

@@ -36,3 +43,3 @@

```js
define(["path/to/dist/duratiform.js"], function(duratiform) {
define(['path/to/dist/duratiform.js'], function(duratiform) {
...

@@ -53,13 +60,23 @@ });

### Example
### Examples <a name="examples"></a>
```js
var nDuration = 123456789000;
console.log("Duration parts: ", duratiform.divide(nDuration, 4)); // { day: 1428, hour: 21, minute: 33, second: 9 }
console.log(nDuration, " - ", duratiform.format(nDuration, "d [days] h [hours] m [minutes] s [seconds]")); // 1428 days 21 hours 33 minutes 9 seconds
console.log("120184000, 4 parts - ", duratiform.divide(120184000, 4)); // { day: 1, hour: 9, minute: 23, second: 4 }
console.log("120184000, 4 parts and strings - ", duratiform.divide(120184000, 4, true)); // { day: 1, day2: "01", hour: 9, hour2: "09", minute: 23, minute2: "23", second: 4, second2: "04" }
console.log("120184000, 3 parts - ", duratiform.divide(120184000, 3)); // { hour: 33, minute: 23, second: 4 }
console.log("4567890 - ", duratiform.format(4567890, "(h:h:)(m:mm:)(s:ss)")); // 1:16:07
console.log("456789 - ", duratiform.format(456789, "(h:h:)(m:mm:)(s:ss)")); // 07:36
console.log('5 duration parts: ', duratiform.divide(nDuration, 5)); // { week: 204, day: 0, hour: 21, minute: 33, second: 9 }
console.log(nDuration, ' - ', duratiform.format(nDuration, 'w [weeks] d [days] h [hours] m [minutes] s [seconds]')); // 204 weeks 0 days 21 hours 33 minutes 9 seconds
console.log('4 duration parts: ', duratiform.divide(nDuration, 4)); // { day: 1428, hour: 21, minute: 33, second: 9 }
console.log(nDuration, ' - ', duratiform.format(nDuration, 'd [days] h [hours] m [minutes] s [seconds]')); // 1428 days 21 hours 33 minutes 9 seconds
console.log('120184000, 4 parts - ', duratiform.divide(120184000, 4)); // { day: 1, hour: 9, minute: 23, second: 4 }
console.log('120184000, 4 parts and strings - ', duratiform.divide(120184000, 4, true)); // { day: 1, day2: "01", hour: 9, hour2: "09", minute: 23, minute2: "23", second: 4, second2: "04" }
console.log('120184000, 3 parts - ', duratiform.divide(120184000, 3)); // { hour: 33, minute: 23, second: 4 }
console.log('4567890 - ', duratiform.format(4567890, '(h:h:)(m:mm:)(s:ss)')); // 1:16:07
console.log('456789 - ', duratiform.format(456789, '(h:h:)(m:mm:)(s:ss)')); // 07:36
console.log('456789 - ', duratiform.format(456789, '(h:h:(m:mm:)(s:ss))')); // empty string
console.log('4567890 - ', duratiform.format(4567890, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))')); // Duration: 1 hr 16 min 07 sec
console.log('456789 - ', duratiform.format(456789, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))')); // Duration: 7 min 36 sec
console.log('6789 - ', duratiform.format(6789, 'Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))')); // Duration: 6 sec
```

@@ -71,11 +88,11 @@

### divide(nDuration: number, [nPartQty: number], [bAddStrings: boolean]): object
### [divide(nDuration: number, [nPartQty: number], [bAddStrings: boolean]): object](https://gamtiq.github.io/duratiform/module-duratiform.html#.divide)
Separate time duration into parts.
### format(nDuration: number, [sFormat: string]): string
### [format(nDuration: number, [sFormat: string]): string](https://gamtiq.github.io/duratiform/module-duratiform.html#.format)
Convert time duration into string.
See `doc` folder for details.
See [`docs`](https://gamtiq.github.io/duratiform/) for details.

@@ -82,0 +99,0 @@ ## License

@@ -9,4 +9,5 @@ /*global chai, describe, it, window*/

nDay = 24 * nHour,
nWeek = 7 * nDay,
lib, expect;
// node

@@ -22,4 +23,4 @@ if (typeof chai === "undefined") {

}
describe(".divide", function() {

@@ -103,4 +104,25 @@ var divide = lib.divide;

describe("divide(nDuration, 1|2|3|4, true)", function() {
describe("divide(nDuration, 5)", function() {
it("should return object with correct 'week', 'day', 'hour', 'minute' and 'second' fields", function() {
expect( divide(3 * nWeek + 6 * nDay + 17 * nHour + 47 * nMinute + 57 * nSecond, 5) )
.eql({week: 3, day: 6, hour: 17, minute: 47, second: 57});
expect( divide(1 * nDay, 5) )
.eql({week: 0, day: 1, hour: 0, minute: 0, second: 0});
expect( divide(2 * nWeek + 6 * nDay + 25 * nHour + 6 * nMinute + 3 * nSecond, 5) )
.eql({week: 3, day: 0, hour: 1, minute: 6, second: 3});
expect( divide(7 * nDay + 65 * nMinute + 42 * nSecond, 5) )
.eql({week: 1, day: 0, hour: 1, minute: 5, second: 42});
expect( divide(23 * nHour + 24 * nMinute + 25 * nSecond, 5) )
.eql({week: 0, day: 0, hour: 23, minute: 24, second: 25});
expect( divide(4 * nWeek + 4 * nMinute + 9 * nSecond, 5) )
.eql({week: 4, day: 0, hour: 0, minute: 4, second: 9});
});
});
describe("divide(nDuration, 1|2|3|4|5, true)", function() {
it("should return object with correct 'day', 'day2', 'hour', 'hour2', 'minute', 'minute2', 'second' and 'second2' fields", function() {
expect( divide(4 * nWeek + 4 * nMinute + 9 * nSecond, 5, true) )
.eql({week: 4, week2: "04", day: 0, day2: "00", hour: 0, hour2: "00", minute: 4, minute2: "04", second: 9, second2: "09"});
expect( divide(11 * nWeek + 2 * nDay + 17 * nHour + 7 * nMinute + 57 * nSecond, 5, true) )
.eql({week: 11, week2: "11", day: 2, day2: "02", hour: 17, hour2: "17", minute: 7, minute2: "07", second: 57, second2: "57"});
expect( divide(5 * nDay + 17 * nHour + 4 * nMinute + 28 * nSecond, 4, true) )

@@ -127,3 +149,3 @@ .eql({day: 5, day2: "05", hour: 17, hour2: "17", minute: 4, minute2: "04", second: 28, second2: "28"});

});
describe(".format", function() {

@@ -294,64 +316,504 @@ var format = lib.format;

});
it("should return correct result string", function() {
expect( format(3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond, "\\day\\s: dd, \\hour\\s: hh, \\minute\\s: mm, \\secon\\d\\s: ss") )
.equal("days: 03, hours: 05, minutes: 46, seconds: 37");
expect( format(3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond, "[days]: dd, [hours]: hh, [minutes]: mm, [seconds]: ss") )
.equal("days: 03, hours: 05, minutes: 46, seconds: 37");
expect( format(3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond, "[days: dd], [hours: hh], [minutes: mm], [seconds: ss]") )
.equal("days: dd, hours: hh, minutes: mm, seconds: ss");
expect( format(3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond, "[days: dd, hours: hh, minutes: mm, seconds: ss") )
.equal("days: dd, hours: hh, minutes: mm, seconds: ss");
expect( format(14 * nDay + 7 * nHour + 9 * nMinute + 28 * nSecond, "\\day\\s: d, \\hour\\s: h, \\minute\\s: m, \\secon\\d\\s: s") )
.equal("days: 14, hours: 7, minutes: 9, seconds: 28");
expect( format(3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond, "Day\\s: dd, Hour\\s: hh, Minute\\s: mm, Secon\\d\\s: ss") )
.equal("Days: 03, Hours: 05, Minutes: 46, Seconds: 37");
expect( format(23 * nDay + 8 * nHour + 7 * nMinute + 36 * nSecond, "DAYS: d, HOURS: h, MINUTES: m, SECONDS: s") )
.equal("DAYS: 23, HOURS: 8, MINUTES: 7, SECONDS: 36");
expect( format(7 * nDay + 3 * nHour + 41 * nMinute + 9 * nSecond, "-d:hh:mm:ss") )
.equal("-7:03:41:09");
expect( format(13 * nHour + 8 * nMinute + 5 * nSecond, "\\[\\dur: h:m:ss\\]") )
.equal("[dur: 13:8:05]");
expect( format(35 * nDay + 16 * nHour + 2 * nMinute + 8 * nSecond, "d-h-m-s") )
.equal("35-16-2-8");
expect( format(8 * nDay + 15 * nHour + 4 * nMinute + 52 * nSecond, "dd\\\\hh\\\\mm\\\\ss") )
.equal("08\\15\\04\\52");
expect( format(2 * nDay + 22 * nHour + 9 * nMinute + 56 * nSecond, "\\d-h-m-s") )
.equal("d-70-9-56");
expect( format(nDay + 5 * nHour + 15 * nMinute, "[[days\\]]: -, [hours]: h, [seconds]: ss") )
.equal("[days]: -, hours: 29, seconds: 00");
expect( format(7 * nDay + 23 * nHour + 10 * nMinute, "[[days]: d]: dd, [hours]: h, minute: s") )
.equal("[days: 7]: 07, hours: 23, 10inute: 0");
expect( format(7 * nDay + 23 * nHour + 10 * nMinute, "[[days\\]: d]: dd, [hours]: h, \\minute: s") )
.equal("[days]: d: 07, hours: 23, minute: 0");
expect( format(nDay, "- [hours]: h, [hours]: h, [hours]: h\\h\\") )
.equal("- hours: 24, hours: 24, hours: 24h");
expect( format(365 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond, "Строка без специальных символов") )
.equal("Строка без специальных символов");
expect( format(365 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond, "дни: d, часы: h, минуты: m, секунды: s") )
.equal("дни: 365, часы: 23, минуты: 59, секунды: 59");
expect( format(3 * nDay + 16 * nHour + 4 * nMinute + 27 * nSecond, "(d:[days - ]d;)(h: [hours - ]h;)(m: [minutes - ]mm;)(s: [seconds - ]ss)") )
.equal("days - 3; hours - 16; minutes - 04; seconds - 27");
expect( format(1 * nDay + 4 * nHour + 8 * nMinute + 41 * nSecond, "(h:h [hour(s) ])(m:mm[ minute(s)])") )
.equal("28 hour(s) 08 minute(s)");
expect( format(1 * nDay + 4 * nHour + 8 * nMinute + 41 * nSecond, "(m:(h:h [hour(s) ])mm[ minute(s)])") )
.equal("28 hour(s) 08 minute(s)");
expect( format(49 * nMinute + 6 * nSecond, "(h:h [hour(s) ])(m:mm[ minute(s)])") )
.equal("49 minute(s)");
expect( format(49 * nMinute + 6 * nSecond, "(m:(h:h [hour(s) ])mm[ minute(s)])") )
.equal("49 minute(s)");
expect( format(49 * nMinute + 6 * nSecond, "(m\\: (s\\: ))") )
.equal("(49: (6: ))");
expect( format(15 * nHour + 3 * nMinute + 57 * nSecond, "(d:d:)(h:h:)(m:mm:)(s:ss)") )
.equal("15:03:57");
expect( format(3 * nMinute + 57 * nSecond, "(d:d:)(h:h:)(m:mm:)(s:ss)") )
.equal("03:57");
expect( format(15 * nHour + 3 * nMinute + 57 * nSecond, "(h:h:(m:mm:(s:ss") )
.equal("15:03:57");
expect( format(15 * nHour + 3 * nMinute + 57 * nSecond, "(h:h:(m:mm:)(s:ss") )
.equal("15:03:57");
expect( format(39 * nMinute + 3 * nSecond, "(d:[days - ]d; )(h:[hours - ]h; )(m:[(m:)inutes - ]mm(m:(m:)!); )(s:[second(s:) - ]ss(m:(s:(h:=).).).)") )
.equal("(m:)inutes - 39!; second(s:) - 03...");
it("should return correct 'ww:dd:hh:mm:ss' string", function() {
expect( format(nMinute, "ww:dd:hh:mm:ss") )
.equal("00:00:00:01:00");
expect( format(nHour, "ww:dd:hh:mm:ss") )
.equal("00:00:01:00:00");
expect( format(nDay, "ww:dd:hh:mm:ss") )
.equal("00:01:00:00:00");
expect( format(nWeek, "ww:dd:hh:mm:ss") )
.equal("01:00:00:00:00");
expect( format(23 * nHour + 59 * nMinute + 59 * nSecond, "ww:dd:hh:mm:ss") )
.equal("00:00:23:59:59");
expect( format(10 * nWeek + 2 * nDay + 22 * nHour + 5 * nMinute + 37 * nSecond, "ww:dd:hh:mm:ss") )
.equal("10:02:22:05:37");
expect( format(15 * nDay + 43 * nMinute + 6 * nSecond, "ww:dd:hh:mm:ss") )
.equal("02:01:00:43:06");
expect( format(79 * nWeek + 4 * nDay + 5 * nHour + 12 * nSecond, "ww:dd:hh:mm:ss") )
.equal("79:04:05:00:12");
expect( format(16 * nDay + 19 * nHour + 43 * nMinute, "ww:dd:hh:mm:ss") )
.equal("02:02:19:43:00");
expect( format(0, "ww:dd:hh:mm:ss") )
.equal("00:00:00:00:00");
});
it("should return correct 'ww:dd:hh:mm' string", function() {
expect( format(nMinute, "ww:dd:hh:mm") )
.equal("00:00:00:01");
expect( format(nHour, "ww:dd:hh:mm") )
.equal("00:00:01:00");
expect( format(nDay, "ww:dd:hh:mm") )
.equal("00:01:00:00");
expect( format(nWeek, "ww:dd:hh:mm") )
.equal("01:00:00:00");
expect( format(23 * nHour + 59 * nMinute + 59 * nSecond, "ww:dd:hh:mm") )
.equal("00:00:23:59");
expect( format(10 * nWeek + 2 * nDay + 22 * nHour + 5 * nMinute + 37 * nSecond, "ww:dd:hh:mm") )
.equal("10:02:22:05");
expect( format(15 * nDay + 43 * nMinute + 6 * nSecond, "ww:dd:hh:mm") )
.equal("02:01:00:43");
expect( format(79 * nWeek + 4 * nDay + 5 * nHour + 12 * nSecond, "ww:dd:hh:mm") )
.equal("79:04:05:00");
expect( format(16 * nDay + 19 * nHour + 43 * nMinute, "ww:dd:hh:mm") )
.equal("02:02:19:43");
expect( format(0, "ww:dd:hh:mm") )
.equal("00:00:00:00");
});
it("should return correct 'ww:dd:hh' string", function() {
expect( format(nMinute, "ww:dd:hh") )
.equal("00:00:00");
expect( format(nHour, "ww:dd:hh") )
.equal("00:00:01");
expect( format(nDay, "ww:dd:hh") )
.equal("00:01:00");
expect( format(nWeek, "ww:dd:hh") )
.equal("01:00:00");
expect( format(23 * nHour + 59 * nMinute + 59 * nSecond, "ww:dd:hh") )
.equal("00:00:23");
expect( format(10 * nWeek + 2 * nDay + 22 * nHour + 5 * nMinute + 37 * nSecond, "ww:dd:hh") )
.equal("10:02:22");
expect( format(15 * nDay + 43 * nMinute + 6 * nSecond, "ww:dd:hh") )
.equal("02:01:00");
expect( format(79 * nWeek + 4 * nDay + 5 * nHour + 12 * nSecond, "ww:dd:hh") )
.equal("79:04:05");
expect( format(16 * nDay + 19 * nHour + 43 * nMinute, "ww:dd:hh") )
.equal("02:02:19");
expect( format(0, "ww:dd:hh") )
.equal("00:00:00");
});
it("should return correct 'ww:dd' string", function() {
expect( format(nHour, "ww:dd") )
.equal("00:00");
expect( format(nDay, "ww:dd") )
.equal("00:01");
expect( format(nWeek, "ww:dd") )
.equal("01:00");
expect( format(23 * nHour + 59 * nMinute + 59 * nSecond, "ww:dd") )
.equal("00:00");
expect( format(10 * nWeek + 2 * nDay + 22 * nHour + 5 * nMinute + 37 * nSecond, "ww:dd") )
.equal("10:02");
expect( format(15 * nDay + 43 * nMinute + 6 * nSecond, "ww:dd") )
.equal("02:01");
expect( format(79 * nWeek + 4 * nDay + 5 * nHour + 12 * nSecond, "ww:dd") )
.equal("79:04");
expect( format(16 * nDay + 19 * nHour + 43 * nMinute, "ww:dd") )
.equal("02:02");
});
it("should return correct 'ww' string", function() {
expect( format(nDay, "ww") )
.equal("00");
expect( format(nWeek, "ww") )
.equal("01");
expect( format(23 * nHour + 59 * nMinute + 59 * nSecond, "ww") )
.equal("00");
expect( format(10 * nWeek + 2 * nDay + 22 * nHour + 5 * nMinute + 37 * nSecond, "ww") )
.equal("10");
expect( format(15 * nDay + 43 * nMinute + 6 * nSecond, "ww") )
.equal("02");
expect( format(79 * nWeek + 4 * nDay + 5 * nHour + 12 * nSecond, "ww") )
.equal("79");
expect( format(16 * nDay + 19 * nHour + 43 * nMinute, "ww") )
.equal("02");
});
describe("should return correct result string", function() {
var testList = [
{
duration: 3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond,
format: "\\day\\s: dd, \\hour\\s: hh, \\minute\\s: mm, \\secon\\d\\s: ss",
result: "days: 03, hours: 05, minutes: 46, seconds: 37"
},
{
duration: 3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond,
format: "[days]: dd, [hours]: hh, [minutes]: mm, [seconds]: ss",
result: "days: 03, hours: 05, minutes: 46, seconds: 37"
},
{
duration: 3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond,
format: "[days: dd], [hours: hh], [minutes: mm], [seconds: ss]",
result: "days: dd, hours: hh, minutes: mm, seconds: ss"
},
{
duration: 3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond,
format: "[days: dd, hours: hh, minutes: mm, seconds: ss",
result: "days: dd, hours: hh, minutes: mm, seconds: ss"
},
{
duration: 14 * nDay + 7 * nHour + 9 * nMinute + 28 * nSecond,
format: "\\day\\s: d, \\hour\\s: h, \\minute\\s: m, \\secon\\d\\s: s",
result: "days: 14, hours: 7, minutes: 9, seconds: 28"
},
{
duration: 14 * nDay + 7 * nHour + 9 * nMinute + 28 * nSecond,
format: "[weeks]: w, [days]: d, [hours]: h, [minutes]: m, [seconds]: s",
result: "weeks: 2, days: 0, hours: 7, minutes: 9, seconds: 28"
},
{
duration: 4 * nDay + 7 * nHour + 9 * nMinute + 28 * nSecond,
format: "[weeks]: w, [days]: d, [hours]: hh, [minutes]: mm, [seconds]: ss",
result: "weeks: 0, days: 4, hours: 07, minutes: 09, seconds: 28"
},
{
duration: 3 * nDay + 5 * nHour + 46 * nMinute + 37 * nSecond,
format: "Day\\s: dd, Hour\\s: hh, Minute\\s: mm, Secon\\d\\s: ss",
result: "Days: 03, Hours: 05, Minutes: 46, Seconds: 37"
},
{
duration: 23 * nDay + 8 * nHour + 7 * nMinute + 36 * nSecond,
format: "DAYS: d, HOURS: h, MINUTES: m, SECONDS: s",
result: "DAYS: 23, HOURS: 8, MINUTES: 7, SECONDS: 36"
},
{
duration: 7 * nDay + 3 * nHour + 41 * nMinute + 9 * nSecond,
format: "-d:hh:mm:ss",
result: "-7:03:41:09"
},
{
duration: 13 * nHour + 8 * nMinute + 5 * nSecond,
format: "\\[\\dur: h:m:ss\\]",
result: "[dur: 13:8:05]"
},
{
duration: 35 * nDay + 16 * nHour + 2 * nMinute + 8 * nSecond,
format: "d-h-m-s",
result: "35-16-2-8"
},
{
duration: 8 * nDay + 15 * nHour + 4 * nMinute + 52 * nSecond,
format: "dd\\\\hh\\\\mm\\\\ss",
result: "08\\15\\04\\52"
},
{
duration: 2 * nDay + 22 * nHour + 9 * nMinute + 56 * nSecond,
format: "\\d-h-m-s",
result: "d-70-9-56"
},
{
duration: nDay + 5 * nHour + 15 * nMinute,
format: "[[days\\]]: -, [hours]: h, [seconds]: ss",
result: "[days]: -, hours: 29, seconds: 00"
},
{
duration: 7 * nDay + 23 * nHour + 10 * nMinute,
format: "[[days]: d]: dd, [hours]: h, minute: s",
result: "[days: 7]: 07, hours: 23, 10inute: 0"
},
{
duration: 7 * nDay + 23 * nHour + 10 * nMinute,
format: "[[days\\]: d]: dd, [hours]: h, \\minute: s",
result: "[days]: d: 07, hours: 23, minute: 0"
},
{
duration: nDay,
format: "- [hours]: h, [hours]: h, [hours]: h\\h\\",
result: "- hours: 24, hours: 24, hours: 24h"
},
{
duration: 365 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond,
format: "Строка без специальных символов",
result: "Строка без специальных символов"
},
{
duration: 365 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond,
format: "дни: d, часы: h, минуты: m, секунды: s",
result: "дни: 365, часы: 23, минуты: 59, секунды: 59"
},
{
duration: 365 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond,
format: "недели: w, дни: d, часы: h, минуты: m, секунды: s",
result: "недели: 52, дни: 1, часы: 23, минуты: 59, секунды: 59"
},
{
duration: 7 * nWeek + 3 * nDay + 8 * nHour + 4 * nMinute + 7 * nSecond,
format: "(w:[weeks - ]w;)(d: [days - ]dd;)(h: [hours - ]hh;)(m: [minutes - ]mm;)(s: [seconds - ]ss)",
result: "weeks - 7; days - 03; hours - 08; minutes - 04; seconds - 07"
},
{
duration: 3 * nDay + 16 * nHour + 4 * nMinute + 27 * nSecond,
format: "(w:[weeks - ]w;)(d:(w: )[days - ]d;)(h: [hours - ]h;)(m: [minutes - ]mm;)(s: [seconds - ]ss)",
result: "days - 3; hours - 16; minutes - 04; seconds - 27"
},
{
duration: 3 * nDay + 16 * nHour + 4 * nMinute + 27 * nSecond,
format: "(d:[days - ]d;)(h: [hours - ]h;)(m: [minutes - ]mm;)(s: [seconds - ]ss)",
result: "days - 3; hours - 16; minutes - 04; seconds - 27"
},
{
duration: 1 * nDay + 4 * nHour + 8 * nMinute + 41 * nSecond,
format: "(h:h [hour(s) ])(m:mm[ minute(s)])",
result: "28 hour(s) 08 minute(s)"
},
{
duration: 1 * nDay + 4 * nHour + 8 * nMinute + 41 * nSecond,
format: "(m:(h:h [hour(s) ])mm[ minute(s)])",
result: "28 hour(s) 08 minute(s)"
},
{
duration: 49 * nMinute + 6 * nSecond,
format: "(h:h [hour(s) ])(m:mm[ minute(s)])",
result: "49 minute(s)"
},
{
duration: 49 * nMinute + 6 * nSecond,
format: "(m:(h:h [hour(s) ])mm[ minute(s)])",
result: "49 minute(s)"
},
{
duration: 49 * nMinute + 6 * nSecond,
format: "(m\\: (s\\: ))",
result: "(49: (6: ))"
},
{
duration: 15 * nHour + 3 * nMinute + 57 * nSecond,
format: "(d:d:)(h:h:)(m:mm:)(s:ss)",
result: "15:03:57"
},
{
duration: 3 * nMinute + 57 * nSecond,
format: "(d:d:)(h:h:)(m:mm:)(s:ss)",
result: "03:57"
},
{
duration: 15 * nHour + 3 * nMinute + 57 * nSecond,
format: "(h:h:(m:mm:(s:ss",
result: "15:03:57"
},
{
duration: 15 * nHour + 3 * nMinute + 57 * nSecond,
format: "(h:h:(m:mm:)(s:ss",
result: "15:03:57"
},
{
duration: 39 * nMinute + 3 * nSecond,
format: "(d:[days - ]d; )(h:[hours - ]h; )(m:[(m:)inutes - ]mm(m:(m:)!); )(s:[second(s:) - ]ss(m:(s:(h:=).).).)",
result: "(m:)inutes - 39!; second(s:) - 03..."
},
{
duration: nDay,
format: "Ti\\meout: (h:h \\hr)(m: m \\min)",
result: "Timeout: 24 hr"
},
{
duration: 5 * nHour + 47 * nSecond,
format: "Duration:(h: h \\hr)(m: mm \\min)",
result: "Duration: 5 hr"
},
{
duration: 5 * nHour + 8 * nMinute + 26 * nSecond,
format: "Duration:(h: h \\hr)(m: mm \\min)",
result: "Duration: 5 hr 08 min"
},
{
duration: 8 * nMinute + 59 * nSecond + 999,
format: "Duration:(h: h \\hr)(m: mm \\min)",
result: "Duration: 08 min"
},
{
duration: 4 * nHour + 8 * nMinute + 9 * nSecond,
format: "Duration:(h: h [hr](m: mm [min]))",
result: "Duration: 4 hr 08 min"
},
{
duration: 4 * nHour + 9 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min))",
result: "Duration: 4 hr"
},
{
duration: 2 * nDay + 4 * nHour + 9 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min))",
result: "Duration: 52 hr"
},
{
duration: 4 * nHour + 9 * nSecond,
format: "Duration:(h: h [hr](m: mm [min])(s: ss [sec]))",
result: "Duration: 4 hr 09 sec"
},
{
duration: 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min))",
result: "Duration:"
},
{
duration: 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min)(s: ss \\sec))",
result: "Duration:"
},
{
duration: 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))",
result: "Duration:"
},
{
duration: 7 * nHour + 53 * nMinute + 2 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))",
result: "Duration: 7 hr 53 min 02 sec"
},
{
duration: 7 * nHour + 12 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))",
result: "Duration: 7 hr"
},
{
duration: 7 * nHour + 5 * nMinute,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))",
result: "Duration: 7 hr 05 min"
},
{
duration: 3 * nMinute,
format: "[!hours (h:h) - ](h:h); [(!m:) ](!h:m)",
result: "!hours (h:h) - ; (!m:) 3"
},
{
duration: 2 * nHour + 3 * nMinute + 59 * nSecond,
format: "[!hours (h:h) - ](h:h); [(!m:) ](!h:m)",
result: "!hours (h:h) - 2; (!m:) "
},
{
duration: 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min))(!h: m \\min)",
result: "Duration: 53 min"
},
{
duration: 7 * nMinute + 27 * nSecond,
format: "Duration:(h: h [hr](m: mm [min]))(!h: m [min])",
result: "Duration: 7 min"
},
{
duration: 4 * nHour + 7 * nMinute + 27 * nSecond,
format: "Duration:(h: h [hr](m: mm [min]))(!h: m [min])",
result: "Duration: 4 hr 07 min"
},
{
duration: 6 * nHour + 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))(!h: (m:m \\min(s: ss \\sec))(!m:s \\sec))",
result: "Duration: 6 hr 53 min 27 sec"
},
{
duration: 19 * nHour + 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))",
result: "Duration: 19 hr 53 min 27 sec"
},
{
duration: 19 * nHour + 2 * nMinute + 5 * nSecond,
format: "Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))",
result: "Duration: 19 hr 02 min 05 sec"
},
{
duration: 53 * nMinute + 27 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))(!h: (m:m \\min(s: ss \\sec))(!m:s \\sec))",
result: "Duration: 53 min 27 sec"
},
{
duration: 8 * nMinute + 27 * nSecond,
format: "Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))",
result: "Duration: 8 min 27 sec"
},
{
duration: 8 * nMinute + 3 * nSecond,
format: "Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))",
result: "Duration: 8 min 03 sec"
},
{
duration: 49 * nSecond,
format: "Duration:(h: h \\hr(m: mm \\min(s: ss \\sec)))(!h: (m:m \\min(s: ss \\sec))(!m:s \\sec))",
result: "Duration: 49 sec"
},
{
duration: 9 * nSecond,
format: "Duration:(h: h [hr](m: mm [min](s: ss [sec])))(!h: (m:m [min](s: ss [sec]))(!m:s [sec]))",
result: "Duration: 9 sec"
},
{
duration: 33 * nDay + 23 * nHour + 48 * nMinute + 15 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "33 day(s) 23 hour(s) 48 minute(s) 15 second(s)"
},
{
duration: 33 * nDay + 48 * nMinute + 15 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "33 day(s) 48 minute(s) 15 second(s)"
},
{
duration: 33 * nDay + 23 * nHour + 15 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "33 day(s) 23 hour(s) 15 second(s)"
},
{
duration: 5 * nDay + 3 * nHour + 8 * nMinute + 1 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "5 day(s) 3 hour(s) 8 minute(s) 1 second(s)"
},
{
duration: 5 * nDay + 3 * nHour,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "5 day(s) 3 hour(s)"
},
{
duration: 5 * nDay + 8 * nMinute,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "5 day(s) 8 minute(s)"
},
{
duration: 5 * nDay + 1 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d: (h:h:mm:ss)(!h:m:ss))",
result: "5 day(s) 1 second(s)"
},
{
duration: 23 * nHour + 48 * nMinute + 15 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d:(h:h:mm:ss)(!h:m:ss))",
result: "23:48:15"
},
{
duration: 8 * nHour + 2 * nMinute + 5 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d:(h:h:mm:ss)(!h:m:ss))",
result: "8:02:05"
},
{
duration: 48 * nMinute + 15 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d:(h:h:mm:ss)(!h:m:ss))",
result: "48:15"
},
{
duration: 2 * nMinute + 5 * nSecond,
format: "(d:d [day(s)](h: h [hour(s)])(m: m [minute(s)])(s: s [second(s)]))(!d:(h:h:mm:ss)(!h:m:ss))",
result: "2:05"
},
{
duration: 9 * nWeek + 14 * nHour + 30 * nSecond,
format: "(w:ww [week(s)](d: d [day(s)]))(!w:(d:d [day(s)])(h:(d: )h [hour(s)]))[ ago]",
result: "09 week(s) ago"
},
{
duration: 9 * nWeek + 14 * nHour + 30 * nSecond,
format: "(w:w [week(s)](d: d [day(s)]))(!w:(d:d [day(s)])(h:(d: )h [hour(s)]))[ ago]",
result: "9 week(s) ago"
},
{
duration: 15 * nWeek + 4 * nDay + 22 * nHour + 49 * nMinute,
format: "(w:w [week(s)](d: dd [day(s)]))(!w:(d:d [day(s)])(h:(d: )h [hour(s)]))[ ago]",
result: "15 week(s) 04 day(s) ago"
},
{
duration: 6 * nDay + 23 * nHour + 59 * nMinute + 59 * nSecond,
format: "(w:w [week(s)](d: d [day(s)]))(!w:(d:d [day(s)])(h:(d: )h [hour(s)]))[ ago]",
result: "6 day(s) 23 hour(s) ago"
},
{
duration: 23 * nHour + 59 * nMinute,
format: "(w:w [week(s)](d: d [day(s)]))(!w:(d:d [day(s)])(h:(d: )h [hour(s)]))[ ago]",
result: "23 hour(s) ago"
}
];
function doTest(nIndex, testItem) {
(testItem.only ? it.only : it)(nIndex + ": " + testItem.duration + ", " + testItem.format + " ---> " + testItem.result, function() {
expect( format(testItem.duration, testItem.format) )
.equal( testItem.result );
});
}
for (var nI = 0, nL = testList.length; nI < nL; nI++) {
doTest(nI, testList[nI]);
}
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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