riptable.rt_timezone
Classes
Stores daylight savings cutoff information so UTC times can be translated to zone-specific times. |
- class riptable.rt_timezone.TimeZone(from_tz=None, to_tz='NYC')
Stores daylight savings cutoff information so UTC times can be translated to zone-specific times. Every
DateTimeNano
object holds aTimeZone
object. All timezone-related conversions / fixups will be handled by theTimeZone
class.- _dst_cutoffs
lookup array for converting times from constructor to UTC nano in GMT time
- Type:
- _timezone_str
same as _to_str. NOTE: This is actually a property, not a regular attribute.
- _dst_reverse
lookup array for DateTimeNano to display time in the correct timezone, accounting for daylight savings.
- Type:
- _offset
offset from GMT for display (non daylight savings)
- _fix_offset
the offset from the timezone of origin
Notes
‘UTC’ is not a timezone, but accepted as an alias for GMT
- property _timezone_str
Get _to_tz, which is the name for this timezone within the ‘tz’ database.
- _ALIAS_TIMEZONE_NAMES
- _TZDB_TIMEZONE_NAMES = ['America/New_York', 'Europe/Dublin', 'UTC', 'GMT', 'Australia/Sydney', 'Asia/Hong_Kong',...
- tz_error_msg
- valid_timezones
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- classmethod _init_from_tz(from_tz)
- classmethod _init_to_tz(to_tz)
Return daylight savings information, timezone string for correctly displaying the datetime based on the to_tz keyword in the constructor.
- _is_dst(arr)
- _mask_dst(arr, cutoffs=None)
- Parameters:
arr – int64 UTC nanoseconds
cutoffs – an array containing daylight savings time starts/ends at midnight possibly a reverse array for GMT that compensates for New York timezone (see DST_REVERSE_NYC)
- _set_timezone(tz)
See DateTimeNano.set_timezone()
- _tz_offset(arr)
- copy()
A shallow copy of the TimeZone - all attributes are scalars or references to constants.
- fix_dst(arr, cutoffs=None)
Called by DateTimeNano routines that need to adjust time for timezone. Also called by DateTimeNanoScalar
- Parameters:
arr (underlying array of int64, UTC nanoseconds OR a scalar np.int64) –
cutoffs (lookup array for daylight savings time cutoffs for the active timezone) –
Notes
There is a difference in daylight savings fixup for Dublin timezone. The python datetime.astimezone() routine works differently than fromutctimestamp(). Python datetime may set a ‘fold’ attribute, indicating that the time is invalid, within an ambiguous daylight savings hour.
>>> import datetime >>> from dateutil import tz
>>> zone = tz.gettz('Europe/Dublin') >>> pdt0 = datetime.datetime(2018, 10, 28, 1, 59, 0, tzinfo=zone) >>> pdt1 = datetime.datetime(2018, 10, 28, 2, 59, 0, tzinfo=zone) >>> dtn = DateTimeNano(['2018-10-28 01:59', '2018-10-28 02:59'], from_tz='DUBLIN', to_tz='DUBLIN') >>> utc = datetime.timezone.utc
>>> pdt0.astimezone(utc) datetime.datetime(2018, 10, 28, 0, 59, tzinfo=datetime.timezone.utc)
>>> pdt1.astimezone(utc) datetime.datetime(2018, 10, 28, 1, 59, tzinfo=datetime.timezone.utc)
>>> dtn.astimezone('GMT') DateTimeNano([20181028 00:59:00.000000000, 20181028 02:59:00.000000000])
- static normalize_tz_to_tzdb_name(tz_name)
- to_utc(dtn, inv_mask=None)
Called in the DateTimeNano constructor. If necessary, integer arrays of nanoseconds are converted from their timezone of origin to UTC nanoseconds in GMT. Restores any invalids (0) from the original array. This differs from fix_dst() because it adds the offset to the array.