Flux 0.166, updated date.add and date.sub examples (#4003)

pull/4006/head
Scott Anderson 2022-05-10 08:34:49 -07:00 committed by GitHub
parent ac8bd6b9e0
commit e0682225bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 43 deletions

View File

@ -125,25 +125,25 @@ duration(v: int(v: 24h) / 2)
```
### Add a duration to a time value
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.addDuration()`](/flux/v0.x/stdlib/experimental/addduration/)
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use [`date.add()`](/flux/v0.x/stdlib/date/add/)
to add a duration to a time value.
```js
import "experimental"
import "date"
experimental.addDuration(d: 1w, to: 2021-01-01T00:00:00Z)
date.add(d: 1w, to: 2021-01-01T00:00:00Z)
// Returns 2021-01-08T00:00:00.000000000Z
```
### Subtract a duration from a time value
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.subDuration()`](/flux/v0.x/stdlib/experimental/subduration/)
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use [`date.sub()`](/flux/v0.x/stdlib/date/sub/)
to subtract a duration from a time value.
```js
import "experimental"
import "date"
experimental.subDuration(d: 1w, from: 2021-01-01T00:00:00Z)
date.sub(d: 1w, from: 2021-01-01T00:00:00Z)
// Returns 2020-12-25T00:00:00.000000000Z
```

View File

@ -220,27 +220,27 @@ date.quarter(t: t0)
### Add a duration to a time value
To add a [duration](/flux/v0.x/data-types/basic/duration/) to a time value:
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.addDuration()`](/flux/v0.x/stdlib/experimental/addduration/)
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use [`date.add()`](/flux/v0.x/stdlib/date/add/)
to add a duration to a time value.
```js
import "experimental"
import "date"
experimental.addDuration(d: 1w, to: 2021-01-01T00:00:00Z)
date.add(d: 1w, to: 2021-01-01T00:00:00Z)
// Returns 2021-01-08T00:00:00.000000000Z
```
### Subtract a duration from a time value
To subtract a [duration](/flux/v0.x/data-types/basic/duration/) from a time value:
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.subDuration()`](/flux/v0.x/stdlib/experimental/subduration/)
to subtract a duration from a time value.
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use [`date.sub()`](/flux/v0.x/stdlib/date/sub/)
to subtract a duration from a time value.
```js
import "experimental"
import "date"
experimental.subDuration(d: 1w, from: 2021-01-01T00:00:00Z)
date.sub(d: 1w, from: 2021-01-01T00:00:00Z)
// Returns 2020-12-25T00:00:00.000000000Z
```

View File

@ -10,6 +10,21 @@ aliases:
- /influxdb/cloud/reference/release-notes/flux/
---
## v0.166.0 [2022-05-09]
### Features
- Add InfluxData semantic commit and pull request title validator.
- Add an `Expr` node to the visitor API.
- Add label polymorphism.
- Vectorize remaining arithmetic operators.
### Bug fixes
- Remove `JoinOpSpec.TableNames` in favor of `JoinOpSpec.params` to stay
consistent inside `tableFind()`.
- Fix `SortLimit` for empty input group.
---
## v0.165.0 [2022-04-25]
### Features

View File

@ -8,6 +8,8 @@ menu:
parent: date
weight: 302
flux/v0.x/tags: [date/time]
aliases:
- /flux/v0.x/stdlib/date/addduration/
related:
- /flux/v0.x/stdlib/date/subduration/
introduced: 0.162.0

View File

@ -9,6 +9,8 @@ menu:
parent: date
weight: 302
flux/v0.x/tags: [date/time]
aliases:
- /flux/v0.x/stdlib/date/subduration/
related:
- /flux/v0.x/stdlib/date/addduration/
introduced: 0.162.0

View File

@ -19,7 +19,7 @@ deprecated: 0.162.0
---
{{% warn %}}
This function was promoted to the [`date` package](/flux/v0.x/stdlib/date/addduration/)
This function was promoted to the [`date` package](/flux/v0.x/stdlib/date/add/)
in **Flux v0.162.0**. This experimental version has been deprecated.
{{% /warn %}}

View File

@ -19,7 +19,7 @@ deprecated: 0.162.0
---
{{% warn %}}
This function was promoted to the [`date` package](/flux/v0.x/stdlib/date/subduration/)
This function was promoted to the [`date` package](/flux/v0.x/stdlib/date/sub/)
in **Flux v0.162.0**. This experimental version has been deprecated.
{{% /warn %}}

View File

@ -92,6 +92,7 @@ Batch range is beyond the migration range. Migration is complete.
```js
import "array"
import "date"
import "experimental"
import "influxdata/influxdb/secrets"
@ -131,7 +132,7 @@ batchRange = () => {
else
migration.start
return {start: _batchStart, stop: experimental.addDuration(d: migration.batchInterval, to: _batchStart)}
return {start: _batchStart, stop: date.add(d: migration.batchInterval, to: _batchStart)}
}
// Define a static record with batch start and stop time properties

View File

@ -1,15 +1,16 @@
---
title: Manipulate timestamps with Flux
list_title: Manipulate timestamps
title: Operate on timestamps with Flux
list_title: Operate on timestamps
description: >
Use Flux to process and manipulate timestamps.
Use Flux to process and operate on timestamps.
menu:
influxdb_2_2:
name: Manipulate timestamps
name: Operate on timestamps
parent: Query with Flux
weight: 220
aliases:
- /influxdb/v2.2/query-data/guides/manipulate-timestamps/
- /influxdb/v2.2/query-data/flux/manipulate-timestamps/
related:
- /{{< latest "flux" >}}/stdlib/universe/now/
- /{{< latest "flux" >}}/stdlib/system/time/
@ -18,12 +19,12 @@ related:
- /{{< latest "flux" >}}/stdlib/universe/int/
- /{{< latest "flux" >}}/stdlib/universe/truncatetimecolumn/
- /{{< latest "flux" >}}/stdlib/date/truncate/
- /{{< latest "flux" >}}/stdlib/experimental/addduration/
- /{{< latest "flux" >}}/stdlib/experimental/subduration/
- /{{< latest "flux" >}}/stdlib/date/add/
- /{{< latest "flux" >}}/stdlib/date/sub/
---
Every point stored in InfluxDB has an associated timestamp.
Use Flux to process and manipulate timestamps to suit your needs.
Use Flux to process and operate on timestamps to suit your needs.
- [Convert timestamp format](#convert-timestamp-format)
- [Calculate the duration between two timestamps](#calculate-the-duration-between-two-timestamps)
@ -159,35 +160,25 @@ data
- [Subtract a duration from a timestamp](#subtract-a-duration-from-a-timestamp)
### Add a duration to a timestamp
The [`experimental.addDuration()` function](/{{< latest "flux" >}}/stdlib/experimental/to/addduration/)
[`date.add()`](/{{< latest "flux" >}}/stdlib/date/add/)
adds a duration to a specified time and returns the resulting time.
{{% warn %}}
By using `experimental.addDuration()`, you accept the
[risks of experimental functions](/{{< latest "flux" >}}/stdlib/experimental/to/#experimental-functions-are-subject-to-change).
{{% /warn %}}
```js
import "experimental"
import "date"
experimental.addDuration(d: 6h, to: 2019-09-16T12:00:00Z)
date.add(d: 6h, to: 2019-09-16T12:00:00Z)
// Returns 2019-09-16T18:00:00.000000000Z
```
### Subtract a duration from a timestamp
The [`experimental.subDuration()` function](/{{< latest "flux" >}}/stdlib/experimental/to/subduration/)
[`date.sub()`](/{{< latest "flux" >}}/stdlib/date/sub/)
subtracts a duration from a specified time and returns the resulting time.
{{% warn %}}
By using `experimental.subDuration()`, you accept the
[risks of experimental functions](/{{< latest "flux" >}}/stdlib/experimental/to/#experimental-functions-are-subject-to-change).
{{% /warn %}}
```js
import "experimental"
import "date"
experimental.subDuration(d: 6h, from: 2019-09-16T12:00:00Z)
date.sub(d: 6h, from: 2019-09-16T12:00:00Z)
// Returns 2019-09-16T06:00:00.000000000Z
```