Tinderbox v9 Icon

Interval.format(formatStr)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

 Function  [other Function type actions]

 Item  [operators of similar scope]

 Formatting  [other Formatting operators]

 Baseline

 As at baseline


Interval.format(formatStr)

For this data type formatStr strings can use date-type format strings. The function returns Interval as a String formatted as per the quoted date/interval format string formatStr.

This supplements the existing format() function.

When used with Interval data, .format() expects the interval to be less than one hours and thus comprising only minutes and seconds data. Further more, only two date format strings are accepted: Interval.format ("l") and Interval.format ("L") which format the mm:ss interval according to the current locale. The lower-case "l" format uses the locale's abbreviated form, while "L" spells out the interval in a phrase customised to local usage.

If $MyInterval is "12:55:23:"

$MyString = $MyInterval.format("l"); gives "12:55"

$MyString = $MyInterval.format("L"); gives "12 hours, 55 minutes"

An Interval value of "00:00" (minutes:seconds)—i.e. that data type's default—always returns an empty string. This if $MyInterval the default 00:00 then:

$MyString = $MyInterval.format("l"); 

results in "", i.e. no value is set in $MyString.

Formatting Intervals of over one hour

The expectation of input as being only mm:ss only can cause confusion when using .format(). If the value of $MyInterval is "12:55:40" (12 hours, 55 minutes and 14 seconds):

$MyString = $MyInterval.format("l") 

The resulting $MyString value is "12:56", i.e. the seconds are rounded (up or down accordingly) and an hours:minuntes string is returned.

As Interval maximum scope is days/hours/minutes/seconds, if the aim is to get the entire interval duration, simply pass the Interval data direct to a string. This if $MyInterval is "1 day 12:55:23":

$MyString = $MyInterval; 

sets $MyString to "1 day 12:55:23". If only part of the source is needed, a different approach is needed. Thus, if $MyInterval is "1 day 12:55:23" and only the number of whole minutes is needed, some string manipulation is required:

$MyString = $MyInterval.extract("(\d{2}):\d{2}$"); 

setting $MyString to "55". Note that regular expressions are very specific. If the closing '$' is omitted from the regex pattern, this results in a $MyString value of "12" instead of "55". Why? Because the latter pattern returns the first pair of digits followed explicitly by a colon and two more digits. Adding the '$' tells the regex that the literal sequence must come at the end of the source string, resulting in "55" being extracted.