The Interval component represents the length of time that
occurs between two events. For example, if today is April 14 and a sale order will
be due on April 24, then the interval is 10 days (the length of time between now and
the order due date). The Interval component represents a
number of years, months, days, hours, minutes, or seconds; the component does
not represent actual dates. For this reason, the Interval
component does not correct for differing time zones.
The Process Business Language (PBL) provides a special literal syntax to
represent Interval objects in code. Interval literals are enclosed by single-quotes
('). They are formed by a sequence of fields, where each field is a number followed
by a unit suffix. Examples:
intervalTest = '15d' // Fifteen days
intervalTest = '1h30m15s' // One hour, 30 minutes and 15 seconds
intervalTest = '1Y4M3h' // One year, 4 months and 3 hours
Refer to the
Process Business Language (PBL) Reference for a complete description of
Interval literals.
When an Interval object is created from a literal expression,
the values are normalized to fit the internal representation of the
Interval component. Note the following details on how the
Interval component normalizes time values:
- Seconds are stored as Hours/Minutes/Seconds. For example, 6165 seconds
is stored as 1h42m45s.
If the number of seconds is above 60 but total less than one hour, the seconds are stored as a combination of minutes and seconds. For example, 110 seconds is stored as 1m50s.
- If the number of minutes is above 60 before conversion, minutes are stored as Hours/Minutes. For example, 75 minutes is stored as 1h15m.
- Hours are stored as a combination of hours and minutes. For example, 26.5 hours is stored as 26h30m.
- Days remain expressed as days; they are not converted into a different time value. Days are not stored as months because the Interval
component does not know if the month consists of 30 or 31 days. Additionally, Days
are not stored as years because the Interval component does not
know if the year consists of 365 or 366 days.
- Months are stored as Years/Months. For example, 25 months is stored as
2Y1M.
Following are more examples of interval conversions:
- 200M25d36h10m789012s is stored as: 16Y8M25d255h20m12s
- 300d18h is stored as: 300d18h (days are not converted into a
different time value).
- 600m18s is stored as: 10h18s (minutes are stored as hours).
- '1.5h' is stored as: 1h30m (only whole values are
stored. In this case, the fraction of the hour is converted into minutes).
Example 1
In the following example, a time interval is created using the difference between
two dates:
now = 'now'
newYear = Time.valueOf(year : now.year+1, month : Month.JANUARY, day : 1)
timeUntilNewYear = newYear - now
display timeUntilNewYear
Example 2
In the following example, a future date is calculated by adding an Interval to
the current date:
twoMonthsFromNow = 'now' + '2M'