docs-v2/content/flux/v0/stdlib/universe/time.md

4.2 KiB

title description menu weight flux/v0/tags introduced
time() function `time()` converts a value to a time type.
flux_v0_ref
name parent identifier
time universe universe/time
101
type-conversions
0.7.0

time() converts a value to a time type.

Function type signature
(v: A) => time

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

v

({{< req >}}) Value to convert.

Strings must be valid RFC3339 timestamps. Integer and unsigned integer values are parsed as nanosecond epoch timestamps.

Examples

Convert a string to a time value

time(v: "2021-01-01T00:00:00Z")// Returns 2021-01-01T00:00:00Z (time)


Convert an integer to a time value

time(v: 1640995200000000000)// Returns 2022-01-01T00:00:00Z


Convert all values in a column to time

If converting the _value column to time types, use toTime(). If converting columns other than _value, use map() to iterate over each row and time() to convert a column value to a time type.

data
    |> map(fn: (r) => ({r with exampleCol: time(v: r.exampleCol)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time _value *tag exampleCol
2021-01-01T00:00:00Z -2 t1 -2000000000
2021-01-01T00:00:10Z 10 t1 10000000000
2021-01-01T00:00:20Z 7 t1 7000000000
2021-01-01T00:00:30Z 17 t1 17000000000
2021-01-01T00:00:40Z 15 t1 15000000000
2021-01-01T00:00:50Z 4 t1 4000000000
_time _value *tag exampleCol
2021-01-01T00:00:00Z 19 t2 19000000000
2021-01-01T00:00:10Z 4 t2 4000000000
2021-01-01T00:00:20Z -3 t2 -3000000000
2021-01-01T00:00:30Z 19 t2 19000000000
2021-01-01T00:00:40Z 13 t2 13000000000
2021-01-01T00:00:50Z 1 t2 1000000000

Output data

_time _value exampleCol *tag
2021-01-01T00:00:00Z -2 1969-12-31T23:59:58Z t1
2021-01-01T00:00:10Z 10 1970-01-01T00:00:10Z t1
2021-01-01T00:00:20Z 7 1970-01-01T00:00:07Z t1
2021-01-01T00:00:30Z 17 1970-01-01T00:00:17Z t1
2021-01-01T00:00:40Z 15 1970-01-01T00:00:15Z t1
2021-01-01T00:00:50Z 4 1970-01-01T00:00:04Z t1
_time _value exampleCol *tag
2021-01-01T00:00:00Z 19 1970-01-01T00:00:19Z t2
2021-01-01T00:00:10Z 4 1970-01-01T00:00:04Z t2
2021-01-01T00:00:20Z -3 1969-12-31T23:59:57Z t2
2021-01-01T00:00:30Z 19 1970-01-01T00:00:19Z t2
2021-01-01T00:00:40Z 13 1970-01-01T00:00:13Z t2
2021-01-01T00:00:50Z 1 1970-01-01T00:00:01Z t2

{{% /expand %}} {{< /expand-wrapper >}}