%dw 2.0
import * from dw::core::Periods
output application/json
---
{
dayAfterDateTime: |2020-10-05T20:22:34.385Z| + duration({days: 1}),
dayAndHourBeforeDateTime: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1}),
pointInTimeBefore: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1, minutes: 20, seconds: 10}),
emptyDuration: duration({}),
constructDuration: duration({days:4, hours:11, minutes:28}),
selectHoursFromDuration: duration({days:4, hours:11, minutes:28}).hours,
decimalAsPeriod: duration({seconds: 30.5}),
addNegativeValue: duration({ minutes : 1 }) + duration({ seconds : -1 })
}
duration
duration(period: { days?: Number, hours?: Number, minutes?: Number, seconds?: Number }): Period
Creates a Period value that represents a number of days, hours, minutes, or seconds.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
An object such as |
Example
This example shows how duration
behaves with different inputs.
Source
Output
{
"dayAfterDateTime": "2020-10-06T20:22:34.385Z",
"dayAndHourBeforeDateTime": "2020-10-04T19:22:34.385Z",
"pointInTimeBefore": "2020-10-04T19:02:24.385Z",
"emptyDuration": "PT0S",
"constructDuration": "PT107H28M",
"selectHoursFromDuration": 11,
"decimalAsPeriod": "PT30.5S",
"addNegativeValue": 59
}