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

4.2 KiB

title description menu weight flux/v0.x/tags introduced
time() function `time()` converts a value to a time type.
flux_0_x_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 covert 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 ouput" %}}

Input data

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

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 >}}