OPAL timestamp conversion

Converting to timestamp

OPAL uses values of type timestamp to store points in time. Your data may have inputs in units like UNIX epoch seconds, Java or JavaScript milliseconds, or an ISO format timestamp string.

To convert from UNIX epoch seconds to timestamp, use from_seconds():

make_col the_time:from_seconds(some_seconds)

To convert from Java or JavaScript milliseconds, use from_milliseconds():

make_col the_time:from_milliseconds(some_milliseconds)

To convert from ISO format string, use parse_isotime():

make_col the_time:parse_isotime(some_string)

Converting from timestamp

Timestamps are internally stored as nanosecond integers. You can convert a timestamp to nanoseconds in the epoch with a simple cast:

make_col nanoseconds:int64(the_timestamp)

You can convert to seconds by multiplying out nanoseconds, although beware the precision loss incurred in float64 values when dealing with large absolute values.

make_col seconds:1.0e-9*float64(the_timestamp)

You can convert to a string using format_time():

make_col date:format_time(the_timestamp, 'YYYY-MM-DD')