Time and Interval Overview

Studio supports two built-in types for time management:


Times are stored as the number of microseconds since Jan 1, 1970 (also known as UNIX epoch).

Intervals are stored as months, days, and microseconds.

Times

The string representation of a time is ISO 8601 compliant. When converting a string into a time, Studio supports a somewhat relaxed subset of ISO 8601; even dates without separators are accepted. The accepted string formats match those of time literals.

Time Literals

Time literals are specified between single quotes. The following is a list of valid time literals:
    '23:30'
    '23:30:23'
    '23:30:23.001023'
    '23:30:23.001023Z'
    '23:30:23.001023-05'
    '23:30:23.001023-3:30'
    '1995-02-03'
    '1995-02-03 23:30'
    '1995-02-03 23:30:23'
    '1995-02-03 23:30:23.001023'
    '1995-02-03 23:30:23.001023Z'
    '1995-02-03 23:30:23.001023-05'
    '1995-02-03 23:30:23.001023-3:30'
    '1995-02-03T23:30'
    '1995-02-03T23:30:23'
    '1995-02-03T23:30:23.001023'
    '1995-02-03T23:30:23.001023Z'
    '1995-02-03T23:30:23.001023-05'
    '1995-02-03T23:30:23.001023-3:30'
    '19950203T'
    '19950203T233023.001023-330'

Time Zones

Following ISO 8601, time zones are specified as offsets from UTC. Named time zones are not supported because there is no international standard for time zone abbreviations. If no time zone is specified in a time literal, the default time zone for the current locale is used.

Note that:


  • Interactive methods run in the locale of the current user.
  • Automatic methods run in the Process Execution Engine's locale.

When a time is presented to a user, the format associated to the user’s locale is used. For custom time formatting, the format function can be used. For further information, please see Time Functions.

Intervals

Intervals have two primary parts:


  • Two calendar dependent components (months and days)
  • A calendar independent component (hours, minutes, seconds and microseconds)

The calendar dependent component exists, so arithmetic between time and interval is consistent. When using a Gregorian calendar (the most common calendar in use), you cannot assume that a month equals to 30 days. In fact, you cannot even assume that a day lasts 24 hours.

The Gregorian calendar inserts two corrections:


  • The leap year - Every four years a day is added to February, unless the year is a multiple of 100 and not a multiple of 400 (which is why the year 2000 had 366 days, instead of 365 like 1900).
  • The leap second - Sometimes a second is added or removed from the last minute of certain days to cope with the accumulated error caused by the Earth's change of speed.
So, for example, if you want to obtain a time two months from now, you can do:
display 'now' + '2M'

Interval Literals

Interval literals are enclosed by single-quotes ('). They are formed by a sequence of fields, where each field is a number plus a unit suffix. The following table lists all valid suffixes:

Unit Suffix Description
Y Years
M Months
d or D Days
h or H Hours
m Minutes
s or S Seconds
x Microseconds
Note: A 'T' in the constant forces the interpretation of 'M' to be equal to 'm', e.g.: '2MT2M' equals '2M2m'.

All magnitudes can contain a '.' to express a fractional part, although the fractional part is dropped for days or months.

The following example shows some valid Interval constants:
display '2MT2.5M'
	display '1Y1M3h2m1.500s'
	display '1.5h'

Arithmetic

As mentioned before, time and intervals have some arithmetic rules.

The following table lists the behavior of addition and subtraction with time and interval:

Operations Result Type
Time - Time Interval
Time + Interval (or Interval + Time) Time
Time - Interval Time
Interval + Interval Interval
Interval - Interval Interval

For further information on Time and Interval, please refer to the following:


  • Time Attributes
  • Interval Attributes
  • Time and Interval Functions