update date.truncate with support for duration values

pull/1140/head
Scott Anderson 2020-06-24 05:26:19 -06:00
parent 50b1485a9c
commit 49eade3280
1 changed files with 20 additions and 1 deletions

View File

@ -31,7 +31,7 @@ date.truncate(
### t
The time to operate on.
_**Data type:** Time_
_**Data type:** Time | Duration_
### unit
The unit of time to truncate to.
@ -44,6 +44,8 @@ For example: `1s`, `1m`, `1h`.
{{% /note %}}
## Examples
##### Truncate time values
```js
import "date"
@ -57,3 +59,20 @@ date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1h)
// Returns 2019-06-03T13:00:00.000000000Z
```
##### Truncate time values using durations
```js
import "date"
option now = () => 2020-01-01T00:00:00Z
date.truncate(t: -30s, unit: 1s)
// Returns 2019-12-31T23:59:30.000000000Z
date.truncate(t: -1m, unit: 1m)
// Returns 2019-12-31T23:59:00.000000000Z
date.truncate(t: -1h, unit: 1h)
// Returns 2019-12-31T23:00:00.000000000Z
```