Time duration type

Time duration type documentation.

Overview

The duration type can store a time duration, such as “3 hours” or “2 days and 2 hours”. The duration is stored internally in milliseconds, while users can utilize a user-friendly language representation in the format Xd Xh Xm Xs. Here, 'd' represents days, 'h' for hours, 'm' for minutes, and 's' for seconds.

Available features

NameSupported
Many multiplicityyes
Default valuesyes
Unique flagno
Required flagyes
Indexable flagyes
Sensitive flagyes
Calculated valueyes
Automatic initializationno
Calculated initial valueno
Aggregationno
Default type rulesno
Default display optionsyes

Display options

When dealing with durations, you can customize how they are displayed using the following options:

  • Format up to: This determines the larger unit of time to display. For instance, if the chosen unit is hours, you might see a duration as “40h”. However, if days are the chosen unit, the duration could be displayed as “1d 16h”.

  • Format down to: This specifies the smaller unit of time for display, truncating the rest. For example, if the value is “2h 30m 15s” and the smaller unit is minutes, the display will be “2h 30m”.

  • Default unit: When entering a value without a unit, this unit will be assumed. For instance, if “3” is entered without a unit and the default unit is hours, it will be interpreted as “3d”.

REST API

Read format

The value of this type is represented as the number of milliseconds.

"hoursPerWeek": 10800000

Write format

When writing the value for this type, you should provide the number of milliseconds.

"hoursPerWeek": 10800000

JavaScript API

Read format

The val() method in the wrapper will return the number of milliseconds.

// this will print something like "hoursPerWeek: 10800000"
log('hoursPerWeek: '+record.field('hoursPerWeek').val());

Write format

You should provide the number of milliseconds.

record.field('hoursPerWeek').val(10800000);

Export/Import

Export format

The export format uses the form explained in the overview of the duration type:

  • Xd Xh Xm Xs, where X represents the number of days, hours, minutes, and seconds respectively.
"durationField1","durationField2"
"4h 30m","3d"

Import format

The import format uses the form explained in the overview of the duration type:

  • Xd Xh Xm Xs, where X represents the number of days, hours, minutes, and seconds respectively.
"durationField1","durationField2"
"4h 30m","3d"

Queries

For more information, please refer to the Query Language Documentation.

Available operators

OperatorSupported
equalsyes
notEqualsyes
emptyyes
notEmptyyes
likeno
greateryes
greaterOrEqualsyes
lessyes
lessOrEqualsyes
betweenyes
currentUserFieldno

Query formats

When working with queries, it’s essential to provide the time in milliseconds.

// finds contacts that worked more than 40 hours per week 
var records_sample = sys.data.find('contacts', {'hoursPerWeek': 'greater(144000000)'});
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds contacts that worked more than 40 hours per week 
var query_sample = sys.data.createQuery('contacts')
    .field('hoursPerWeek').greater(144000000)
var records_sample = sys.data.find(query_sample);
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds contacts that worked more than 40 hours per week 
GET /data/contacts?hoursPerWeek=greater(144000000)

Aggregate queries

Please refer to the Aggregate Queries Documentation for more detailed information.

Available operators

OperatorSupported
sumyes
avgyes
firstyes
lastyes
minyes
maxyes

UI queries

Please refer to the UI Queries Documentation for more detailed information.

Matching of values

PropertyDescription
Matching operatorequals
The format is Xd Xh Xm Xs, where X represents the number of days, hours, minutes, and seconds respectively.

Available operators

OperatorSupported
Many valuesyes
Greaterno
Greater or equalsno
Lessyes
Less or equalsyes
Betweenyes