updated other date pkg functions with durations and examples
parent
a548088634
commit
40f4ed3a3c
|
@ -12,7 +12,7 @@ related:
|
|||
- /v2.0/reference/flux/stdlib/system/time/
|
||||
---
|
||||
|
||||
The `now()` function returns the current time (UTC).
|
||||
The `now()` function returns the current time (UTC) or the time defined in the `now` option.
|
||||
|
||||
_**Function type:** Date/Time_
|
||||
_**Output data type:** Time_
|
||||
|
@ -22,11 +22,21 @@ now()
|
|||
```
|
||||
|
||||
## Examples
|
||||
|
||||
##### Use the current UTC time as a query boundary
|
||||
```js
|
||||
data
|
||||
|> range(start: -10h, stop: now())
|
||||
```
|
||||
|
||||
##### Return the now option time
|
||||
```js
|
||||
option now = () => 2020-01-01T00:00:00Z
|
||||
|
||||
now()
|
||||
// Returns 2020-01-01T00:00:00.000000000Z
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
#### now() vs system.time()
|
||||
`now()` returns the current UTC time.
|
||||
|
|
|
@ -29,5 +29,29 @@ date.hour(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the hour of a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.hour(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 12
|
||||
```
|
||||
|
||||
##### Return the hour of a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.hour(t: -8h)
|
||||
|
||||
// Returns 4
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.microsecond(t: 2019-07-17T12:05:21.012934584Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the microsecond of a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.microsecond(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 293534
|
||||
```
|
||||
|
||||
##### Return the microsecond of a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.microsecond(t: -1890us)
|
||||
|
||||
// Returns 291644
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.millisecond(t: 2019-07-17T12:05:21.012934584Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the millisecond of a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.millisecond(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 293
|
||||
```
|
||||
|
||||
##### Return the millisecond of a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.millisecond(t: -150ms)
|
||||
|
||||
// Returns 143
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.month(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the month of a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.month(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 2
|
||||
```
|
||||
|
||||
##### Return the month of a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.month(t: -3mo)
|
||||
|
||||
// Returns 11
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.monthDay(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the day of the month for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.monthDay(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 11
|
||||
```
|
||||
|
||||
##### Return the day of the month for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.monthDay(t: -8d)
|
||||
|
||||
// Returns 3
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.nanosecond(t: 2019-07-17T12:05:21.012934584Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the nanosecond for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.nanosecond(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 293534940Z
|
||||
```
|
||||
|
||||
##### Return the nanosecond for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.nanosecond(t: -2111984ns)
|
||||
|
||||
// Returns 291422956
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.quarter(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the quarter for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.quarter(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 1
|
||||
```
|
||||
|
||||
##### Return the quarter for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.quarter(t: -7mo)
|
||||
|
||||
// Returns 3
|
||||
```
|
||||
|
|
|
@ -51,14 +51,14 @@ For example: `1s`, `1m`, `1h`.
|
|||
```js
|
||||
import "date"
|
||||
|
||||
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1s)
|
||||
// Returns 2019-06-03T13:59:01.000000000Z
|
||||
date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1s)
|
||||
// Returns 2019-06-03T13:59:01.000000000Z
|
||||
|
||||
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1m)
|
||||
// Returns 2019-06-03T13:59:00.000000000Z
|
||||
date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1m)
|
||||
// Returns 2019-06-03T13:59:00.000000000Z
|
||||
|
||||
date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1h)
|
||||
// Returns 2019-06-03T13:00:00.000000000Z
|
||||
date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1h)
|
||||
// Returns 2019-06-03T13:00:00.000000000Z
|
||||
```
|
||||
|
||||
##### Truncate time values using durations
|
||||
|
@ -68,11 +68,11 @@ import "date"
|
|||
option now = () => 2020-01-01T00:00:30.500000000Z
|
||||
|
||||
date.truncate(t: -30s, unit: 1s)
|
||||
// Returns 2019-12-31T23:59:30.000000000Z
|
||||
// Returns 2019-12-31T23:59:30.000000000Z
|
||||
|
||||
date.truncate(t: -1m, unit: 1m)
|
||||
// Returns 2019-12-31T23:59:00.000000000Z
|
||||
// Returns 2019-12-31T23:59:00.000000000Z
|
||||
|
||||
date.truncate(t: -1h, unit: 1h)
|
||||
// Returns 2019-12-31T23:00:00.000000000Z
|
||||
// Returns 2019-12-31T23:00:00.000000000Z
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.weekDay(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the day of the week for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.weekDay(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 2
|
||||
```
|
||||
|
||||
##### Return the day of the week for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.weekDay(t: -84h)
|
||||
|
||||
// Returns 6
|
||||
```
|
||||
|
|
|
@ -27,5 +27,29 @@ date.year(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the year for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.year(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 2020
|
||||
```
|
||||
|
||||
##### Return the year for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.year(t: -14y)
|
||||
|
||||
// Returns 2006
|
||||
```
|
||||
|
|
|
@ -29,5 +29,29 @@ date.yearDay(t: 2019-07-17T12:05:21.012Z)
|
|||
|
||||
### t
|
||||
The time to operate on.
|
||||
Use an absolute time or relative duration.
|
||||
Durations are relative to `now()`.
|
||||
|
||||
_**Data type:** Time_
|
||||
_**Data type:** Time | Duration_
|
||||
|
||||
## Examples
|
||||
|
||||
##### Return the day of the year for a time value
|
||||
```js
|
||||
import "date"
|
||||
|
||||
date.yearDay(t: 2020-02-11T12:21:03.293534940Z)
|
||||
|
||||
// Returns 42
|
||||
```
|
||||
|
||||
##### Return the day of the year for a relative duration
|
||||
```js
|
||||
import "date"
|
||||
|
||||
option now = () => 2020-02-11T12:21:03.293534940Z
|
||||
|
||||
date.yearDay(t: -1mo)
|
||||
|
||||
// Returns 11
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue