FormatDuration

From emotive
Jump to: navigation, search

Classification

Name FormatDuration
Short Description Returns a formatted time representation of a duration in milliseconds.
Class Term
Extension OTX DateTime Extension
Group -
Exceptions OutOfBoundsException
Checker Rules -
Standard Compliant Yes

OTL Syntax

StringTerm DateTime.FormatDuration(NumericTerm duration, StringTerm format);

Description

FormatDuration is a term which converts returns a formatted string of a given milliseconds duration. If no custom format is given, the ISO 8601 conform date output will be formatted equivalent to the custom pattern:

'P'y-MM-dd'T'HH:mm:ss'.'SSS

Where "P" is the duration designator and "T"is the time designator.

Icons Warning.png Results from FormatDuration should not be used for test logic, only for user representations, because exchangeability cannot be guaranteed across different run time systems (e.g. ERA, time zone)!
Icons Note.png The format pattern rules are analogous to the rules given for the class java.text.SimpleDateFormat as specified by the Java™ 2 Platform Standard Ed. 6.

The following table gives an overview of the decoding of the format patterns.

Format pattern specifiers
Specifier(s) Meaning Example
Y Years portion of duration 11, 124
M, MM Months portion of duration, 0-11 count (without / with leading zero) 2, 02
d, dd Days portion of duration, 0-29365 count (without / with leading zero)
3, 09
H, HH Hours portion of duration, 0-23 count (without / with leading zero) 7, 07
m, mm Minutes portion of duration, 0-59 count (without / with leading zero) 2, 02
s, ss Seconds portion of duration, 0-59 count (without / with leading zero) 4, 04
S, SS, SSS Milliseconds of duration, 0-999 count (without / with leading zeros) 357, 034, 002

If the duration value is negative, the OutOfBoundsException exception will be thrown.

Return Value

The Term returns the value, see table below.

Icons Note.png In OTX, Terms are categorized according to its return data type!
Data Type Description
String A formatted duration.

Properties

Name Data Type Class Default Cardinality Description
Duration Integer Term - [1] Specifies a duration in milliseconds which will be formatted according to the specified format pattern.
Format String Term - [0..1] Represents the format string pattern to format the duration.

OTL Examples

/// Local Declarations

String DurationAsString;

/// Flow

DurationAsString = DateTime.FormatDuration(203443, "mm:ss 'mm:ss'"); // returns: "03:23 mm:ss"
DurationAsString = DateTime.FormatDuration(203443); // returns: "P0-00-00T00:03:23.443"

See also

GetTimeStamp
FormatDate