deephaven.time¶
This module defines functions for handling Deephaven date/time data.
- DAY = 86400000000000¶
One day in nanoseconds.
- HOUR = 3600000000000¶
One hour in nanoseconds.
- MINUTE = 60000000000¶
One minute in nanoseconds.
- SECOND = 1000000000¶
One second in nanoseconds.
- class TimeZone(value)[source]¶
Bases:
enum.Enum
A Enum for known time zones.
- AL = io.deephaven.time.TimeZone(objectRef=0x3f5a390)¶
America/Anchorage
- AT = io.deephaven.time.TimeZone(objectRef=0x3f5a380)¶
Canada/Atlantic
- BT = io.deephaven.time.TimeZone(objectRef=0x3f5a360)¶
America/Sao_Paulo
- CE = io.deephaven.time.TimeZone(objectRef=0x3f5a3a0)¶
Europe/Berlin
- CH = io.deephaven.time.TimeZone(objectRef=0x3f5a3c8)¶
Europe/Zurich
- CT = io.deephaven.time.TimeZone(objectRef=0x3f5a340)¶
America/Chicago
- ET = io.deephaven.time.TimeZone(objectRef=0x3f5a330)¶
America/New_York
- HI = io.deephaven.time.TimeZone(objectRef=0x3f5a358)¶
Pacific/Honolulu
- HK = io.deephaven.time.TimeZone(objectRef=0x3f5a370)¶
Asia/Hong_Kong
- IN = io.deephaven.time.TimeZone(objectRef=0x3f5a398)¶
Asia/Kolkata
- JP = io.deephaven.time.TimeZone(objectRef=0x3f5a378)¶
Asia/Tokyo
- KR = io.deephaven.time.TimeZone(objectRef=0x3f5a368)¶
Asia/Seoul
- LON = io.deephaven.time.TimeZone(objectRef=0x3f5a3b0)¶
Europe/London
- MN = io.deephaven.time.TimeZone(objectRef=0x3f5a338)¶
America/Chicago
- MOS = io.deephaven.time.TimeZone(objectRef=0x3f5a3b8)¶
Europe/Moscow
- MT = io.deephaven.time.TimeZone(objectRef=0x3f5a348)¶
America/Denver
- NF = io.deephaven.time.TimeZone(objectRef=0x3f5a388)¶
Canada/Newfoundland
- NL = io.deephaven.time.TimeZone(objectRef=0x3f5a3d0)¶
Europe/Amsterdam
- NY = io.deephaven.time.TimeZone(objectRef=0x3f5a328)¶
America/New_York
- PT = io.deephaven.time.TimeZone(objectRef=0x3f5a350)¶
America/Los_Angeles
- SG = io.deephaven.time.TimeZone(objectRef=0x3f5a3a8)¶
Asia/Singapore
- SHG = io.deephaven.time.TimeZone(objectRef=0x3f5a3c0)¶
Asia/Shanghai
- SYD = io.deephaven.time.TimeZone(objectRef=0x3f5a3e0)¶
Australia/Sydney
- TW = io.deephaven.time.TimeZone(objectRef=0x3f5a3d8)¶
Asia/Taipei
- UTC = io.deephaven.time.TimeZone(objectRef=0x3f5a3e8)¶
UTC
- WEEK = 604800000000000¶
One week in nanoseconds.
- YEAR = 31449600000000000¶
One year in nanoseconds.
- datetime_at_midnight(dt, tz)[source]¶
Returns a DateTime for the requested DateTime at midnight in the specified time zone.
- day_of_month(dt, tz)[source]¶
Returns an 1-based int value of the day of the month for a DateTime and specified time zone.
- day_of_week(dt, tz)[source]¶
- Returns an 1-based int value of the day of the week for a DateTime in the specified time zone, with 1 being
Monday and 7 being Sunday.
- day_of_year(dt, tz)[source]¶
Returns an 1-based int value of the day of the year (Julian date) for a DateTime in the specified time zone.
- diff_nanos(dt1, dt2)[source]¶
Returns the difference in nanoseconds between two DateTime values.
- Parameters
dt1 (DateTime) – the 1st DateTime
dt2 (DateTime) – the 2nd DateTime
- Returns
NULL_LONG if either dt1 or dt2 is None
- Return type
int
- Raises
DHError –
- format_date(dt, tz)[source]¶
Returns a string date representation of a DateTime interpreted for a specified time zone formatted as “yyy-MM-dd”.
- format_datetime(dt, tz)[source]¶
Returns a string DateTime representation formatted as “yyyy-MM-ddThh:mm:ss.SSSSSSSSS TZ”.
- format_nanos(ns)[source]¶
Returns a string DateTime representation formatted as “yyyy-MM-ddThh:mm:ss.SSSSSSSSS”.
- Parameters
ns (int) – the number of nanoseconds
- Return type
str
- Returns
str
- Raises
DHError –
- hour_of_day(dt, tz)[source]¶
Returns the hour of the day for a DateTime in the specified time zone. The hour is on a 24 hour clock (0 - 23).
- is_after(dt1, dt2)[source]¶
Evaluates whether one DateTime value is later than a second DateTime value.
- Parameters
dt1 (DateTime) – the 1st DateTime
dt2 (DateTime) – the 2nd DateTime
- Return type
bool
- Returns
bool
- Raises
DHError –
- is_before(dt1, dt2)[source]¶
Evaluates whether one DateTime value is before a second DateTime value.
- Parameters
dt1 (DateTime) – the 1st DateTime
dt2 (DateTime) – the 2nd DateTime
- Return type
bool
- Returns
bool
- Raises
DHError –
- lower_bin(dt, interval, offset=0)[source]¶
- Returns a DateTime value, which is at the starting (lower) end of a time range defined by the interval
nanoseconds. For example, a 5*MINUTE intervalNanos value would return the DateTime value for the start of the five minute window that contains the input date time.
- Parameters
dt (DateTime) – the DateTime for which to evaluate the start of the containing window
interval (int) – the size of the window in nanoseconds
offset (int) – the window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute. Default is 0
- Return type
- Returns
DateTime
- Raises
DHError –
- millis(dt)[source]¶
Returns milliseconds since Epoch for a DateTime value.
- Parameters
dt (DateTime) – the DateTime for which the milliseconds offset should be returned
- Returns
NULL_LONG if dt is None
- Return type
int
- Raises
DHError –
- millis_of_day(dt, tz)[source]¶
Returns the number of milliseconds since midnight for a DateTime in the specified time zone.
- millis_of_second(dt, tz)[source]¶
Returns the number of milliseconds since the top of the second for a DateTime in the specified time zone.
- millis_to_datetime(ms)[source]¶
Converts a value of milliseconds from Epoch in the UTC time zone to a DateTime.
- millis_to_nanos(ms)[source]¶
Converts milliseconds to nanoseconds.
- Parameters
ms (int) – the milliseconds value to convert
- Returns
NULL_LONG if ms is NULL_LONG
- Return type
int
- Raises
DHError –
- minus(dt1, dt2)[source]¶
Subtracts one time from another, returns the difference in nanos.
- Parameters
dt1 (DateTime) – the 1st DateTime
dt2 (DateTiem) – the 2nd DateTime
- Returns
NULL_LONG if either dt1 or dt2 is None
- Return type
int
- Raises
DHError –
- minute_of_day(dt, tz)[source]¶
Returns the number of minutes since midnight for a DateTime in the specified time zone.
- minute_of_hour(dt, tz)[source]¶
Returns the number of minutes since the top of the hour for a DateTime in the specified time zone.
- month_of_year(dt, tz)[source]¶
Returns an 1-based int value for the month of a DateTime in the specified time zone. January is 1, and December is 12.
- nanos(dt)[source]¶
Returns nanoseconds since Epoch for a DateTime value.
- Parameters
dt (DateTime) – the DateTime for which the nanoseconds offset should be returned
- Returns
NULL_LONG if dt is None
- Return type
int
- Raises
DHError –
- nanos_of_day(dt, tz)[source]¶
Returns the number of nanoseconds since midnight for a DateTime in the specified time zone.
- nanos_of_second(dt, tz)[source]¶
Returns the number of nanoseconds since the top of the second for a DateTime in the specified time zone.
- nanos_to_datetime(ns)[source]¶
Converts a value of nanoseconds from Epoch to a DateTime.
- Parameters
ns (long) – the long nanoseconds since Epoch value to convert
- Return type
- Returns
DateTime
- nanos_to_millis(ns)[source]¶
Converts nanoseconds to milliseconds.
- Parameters
ns (int) – the value of nanoseconds to convert
- Returns
NULL_LONG if ns is NULL_LONG
- Return type
int
- Raises
DHError –
- plus_nanos(dt, ns)[source]¶
Adds nanoseconds to a DateTime.
- Parameters
dt (DateTime) – the starting DateTime value
ns (int) – the number of nanoseconds to add to DateTime
- Returns
None if dt is None or ns is NULL_LONG
- Return type
DateTime
- Raises
DHError –
- plus_period(dt, period)[source]¶
Adds a period to a DateTime.
- Parameters
dt (DateTime) – the starting DateTime value
period (Period) – the Period to add to the DateTime
- Returns
None if either dt or period is None
- Return type
DateTime
- Raises
DHError –
- second_of_day(dt, tz)[source]¶
Returns the number of seconds since midnight for a DateTime in the specified time zone.
- second_of_minute(dt, tz)[source]¶
Returns the number of seconds since the top of the minute for a DateTime in the specified time zone.
- to_datetime(s, quiet=False)[source]¶
Converts a datetime string to a DateTime object.
Supports ISO 8601 format and others.
- to_nanos(s, quiet=False)[source]¶
Converts a time string to nanoseconds.
- Parameters
s (str) – in the format of: hh:mm:ss[.SSSSSSSSS]
quiet (bool) – to return None or raise an exception if the string can’t be parsed, default is False
- Return type
int
- Returns
int
- Raises
DHError –
- to_period(s, quiet=False)[source]¶
Converts a period string into a Period object.
- Parameters
s (str) – a string in the form of nYnMnWnDTnHnMnS, with n being numeric values, e.g. 1W for one week, T1M for one minute, 1WT1H for one week plus one hour
quiet (bool) – when True, if the period string can’t be parsed, this function returns None, otherwise it raises an exception. The default is False
- Return type
- Returns
a Period
- Raises
DHError –
- upper_bin(dt, interval, offset=0)[source]¶
- Returns a DateTime value, which is at the ending (upper) end of a time range defined by the interval
nanoseconds. For example, a 5*MINUTE intervalNanos value would return the DateTime value for the end of the five minute window that contains the input date time.
- Parameters
dt (DateTime) – the DateTime for which to evaluate the end of the containing window
interval (int) – the size of the window in nanoseconds
offset (int) – the window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute. Default is 0
- Returns
DateTime
- Raises
DHError –