duratiform

Methods

(static) divide(nDuration, nPartQtyopt, bAddStringsopt) → {Object}

Source:
Separate time duration into parts.
Parameters:
Name Type Attributes Description
nDuration Integer Time duration in milliseconds.
nPartQty Integer <optional>
Parts quantity. The default value is 3. The following values are allowed:
  • 1 - return seconds quantity (second field)
  • 2 - return quantity of minutes and seconds (minute and second fields)
  • 3 - return quantity of hours, minutes and seconds (hour, minute and second fields)
  • 4 - return quantity of days, hours, minutes and seconds (day, hour, minute and second fields)
  • 5 - return quantity of weeks, days, hours, minutes and seconds (week, day, hour, minute and second fields)
bAddStrings Boolean <optional>
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 and is prefixed with "0" if it is necessary (i.e. values from 0 to 9 are converted to "00"-"09"). The default value is false.
Returns:
Object representing the requested parts of time duration. Can contain the following fields.
Name Type Description
day Integer Quantity of full days
day2 String Quantity of full days. String contains at least 2 characters. This field is included only when bAddStrings has true value.
hour Integer Quantity of full hours
hour2 String Quantity of full hours. String contains at least 2 characters. This field is included only when bAddStrings has true value.
minute Integer Quantity of full minutes
minute2 String Quantity of full minutes. String contains at least 2 characters. This field is included only when bAddStrings has true value.
second Integer Quantity of full seconds
second2 String Quantity of full seconds. String contains at least 2 characters. This field is included only when bAddStrings has true value.
week Integer Quantity of full weeks
week2 String Quantity of full weeks. String contains at least 2 characters. This field is included only when bAddStrings has true value.
Type
Object

(static) format(nDuration, sFormatopt) → {String}

Source:
Convert time duration into string.
Parameters:
Name Type Attributes Description
nDuration Integer Time duration in milliseconds.
sFormat String <optional>
Format of the returned value. The default value is hh:mm:ss.
The following tokens are interpreted in special way:
  • \x - replaced by x, where x is any character
  • d - quantity of days (1 or more characters)
  • dd - quantity of days (2 or more characters)
  • h - quantity of hours (1 or more characters)
  • hh - quantity of hours (2 or more characters)
  • m - quantity of minutes (1 or more characters)
  • mm - quantity of minutes (2 or more characters)
  • s - quantity of seconds (1 or more characters)
  • ss - quantity of seconds (2 or more characters)
  • w - quantity of weeks (1 or more characters)
  • ww - quantity of weeks (2 or more characters)
  • [ - cancel special processing of the following characters (except \x and ]); this character won't be included into the result
  • ] - restore special processing that was previously cancelled by [ character; this character won't be included into the result; thus any sequence of characters that is surrounded by square brackets (except \x and ]) will be included into the result as is but without brackets
  • (x: - where x is one of w (weeks), d (days), h (hours), m (minutes) or s (seconds), begin group of characters that will be included in the result only when the corresponding part of duration is present (above 0)
  • (!x: - where x is one of w (weeks), d (days), h (hours), m (minutes) or s (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)
  • ) - end of previous group; thus by using format (h:h:)mm:ss hours part will be in result only when duration is greater than 60 minutes
All other characters will be included into the result as is.
Returns:
String representing time duration depending of format.
Type
String