Skip to main content
Version: Java (Groovy)

autoEpochToTime

autoEpochToTime converts an offset value from Unix Epoch to a date-time. This method uses expected date ranges to infer whether the passed value is in milliseconds, microseconds, or nanoseconds.

Syntax

autoEpochToTime(offset)

Parameters

ParameterTypeDescription
offsetlong

The offset value to convert to a date-time.

This method uses expected date ranges to infer whether the passed value is in milliseconds, microseconds, or nanoseconds. Thresholds used are TimeConstants.MICROTIME_THRESHOLD:

  • divided by 1000 for milliseconds
  • as-is for microseconds
  • multiplied by 1000 for nanoseconds

The value is tested to see if its ABS exceeds the threshold; e.g., a value whose ABS is greater than 1000 * TimeConstants.MICROTIME_THRESHOLD will be treated as nanoseconds.

Returns

The offset since the Unix Epoch in the UTC time zone converted to a date-time.

note

Null input values will return NULL_LONG.

Examples

The following example demonstrates how Deephaven infers the passed value. All three return the same result.

println autoEpochToTime(150000000) // milliseconds
println autoEpochToTime(150000000000) // microseconds
println autoEpochToTime(150000000000000) // nanoseconds

In the following example, a new column (Time) is added that converts the specified offset value into a date-time.

source = newTable(
stringCol("Ticker", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL"),
dateTimeCol("Timestamp", convertDateTime("2021-04-05T09:10:39.123456700 NY"), convertDateTime("2021-04-05T09:10:50.123456700 NY"), convertDateTime("2021-04-05T09:11:39.123456700 NY"), convertDateTime("2021-04-05T09:11:50.123456700 NY"), convertDateTime("2021-04-05T09:12:39.123456700 NY")),
doubleCol("Price", 100.10, 101.0, 102.40, 100.50, 100.30),
intCol("Size", 52, 14, 73, 11, 6)
)

result = source.update("Time = autoEpochToTime(5000)")