jztools.datetime64#
Module Attributes
A naive date-time as a |
|
The same as |
|
A np.datetime64 in UTC. |
Functions
|
Converts the |
|
Takes an input datetime (as an |
|
Same as |
|
|
|
Returns an integer specification of the date when counting a specific child time resolution in a given parent time resolution. |
|
|
|
Returns the month as an integer in 0,..,11. |
|
Returns the day of the month as an integer in 0,..,30. |
|
|
|
Returns |
Returns a dictionary with fields 'type' ('datetime64' or 'timedelta64'), 'num' (number of date time units) and 'dt_unit' (datetime unit, e.g., 'D', 'm', 's', 'h') |
|
|
|
|
Converts a datetime from US/Eastern (standard or dalyight saving depending on the time) to UTC. |
|
Returns the day of the week as an integer in 0,..,6, with 0 corresponding to the day of the week of the specified reference date (defaults to Monday as 0). |
- jztools.datetime64.FlexDateTime#
A naive date-time as a
numpy.datetime64(string or object) or naivedatetimeor timezone-awaredatetime. All naive values are assumed to be in UTC by convention.alias of
Union[datetime64,datetime,str]
- jztools.datetime64.UTCFlexDateTime#
The same as
FlexDateTimebut with the UTC convention made explicit.alias of
Union[datetime64,datetime,str]
- jztools.datetime64.UTCDateTime64#
A np.datetime64 in UTC.
- jztools.datetime64.date_slot(dates: ndarray, child_resolution: str | dtype, parent_resolution: str | dtype, ref_date=numpy.datetime64('2018-01-01')) Tuple[ndarray, int]#
Returns an integer specification of the date when counting a specific child time resolution in a given parent time resolution. For example, for child resolution of 1 minute in parent resolution of 1 hour, returns an array of integers in 0,…,59 of the same shape as dates.
- Parameters:
dates – A numpy datetime64 array.
parent_resolution (child_resolution,) – A numpy dtype that is a sub-dtype of
numpy.timedelta64, or a string specification of such a dtype. Valid strings include'ns','us','ms','s','m','h','D','M','Y'. Child resolutions can further be any such string prepended with a string integer to indicate non-unit resolutions (e.g.,'10m'). Parent resolutions cannot include an integer. Integer-prepended parent resolutions produce undefined results or raise an exception.ref_date – The reference date representing the position 0 as a
numpy.datetime64object. Defaults tonp.datetime64('2018-01-01')- a Monday.
- Returns:
Returns the dates specified as integer positions of the child time resolution in the parent time resolution, and the total number of children. E.g., for child resolution
'D'and parent resoluiton'W', returns an array integers in the range 0, …, 6 and a number of children equal to 7.
- jztools.datetime64.weekday(dates: ndarray, *args)#
Returns the day of the week as an integer in 0,..,6, with 0 corresponding to the day of the week of the specified reference date (defaults to Monday as 0).
- Parameters:
ref_date – Same as
get_time_slot().
from jztools.datetime64 import weekday assert weekday(np.array(['2018-01-01'], dtype=='datetime64')) == 0
- jztools.datetime64.monthday(dates: ndarray)#
Returns the day of the month as an integer in 0,..,30.
- jztools.datetime64.month(dates: ndarray, *args)#
Returns the month as an integer in 0,..,11.
- jztools.datetime64.as_datetime(dt64: datetime64, tzinfo: str | tzinfo | None = None) date | datetime#
Converts the
np.datetime64object to adatetime.datetime, for dtypes containing hour or higher resolution, ordatetime.dateobject otherwise.If the returned object is a
datetime.datetime, it will be localized to the specifiedtzinfo, if any.
- jztools.datetime64.as_naive_utc(in_datetime: datetime64 | datetime | str, in_tzinfo: str | tzinfo | None = None) datetime64#
Same as
as_naive()but without_tzinfo = pytz.UTC.
- jztools.datetime64.as_naive(in_datetime: datetime64 | datetime | str, in_tzinfo: str | tzinfo | None = None, out_tzinfo: str | tzinfo | None = None) datetime64#
Takes an input datetime (as an
str,datetimeordatetime64) in the specified input timezone and converts it into a naivedatetime64in the specified output timezone. The input datetime can be naive or timezone-aware. If naive, thein_tzinfoparameter must be supplied. Otherwise, that parameter is ignored.- Returns:
If the input contains a time-less date (as a string or a datetime.date object, or an
np.datetime64object of dtype'datetime64[D]'or lower resolution), that same date is returned as anp.datetime64object
of dtype ‘datetime64[D]’ (or of the same dtype, for
np.datetime64inputs. If the input does contain a time, the output dtype isnp.datetime64[us].- Parameters:
in_datetime – A
FlexDateTimewith the input datetime.in_tzinfo – If
in_datetimeis naive, this will need to be supplied. Otherwise, it is ignored.out_tzinfo – The output tzinfo of the supplied datetime object.
- jztools.datetime64.utc_from_eastern(in_datetime: datetime64 | datetime | str)#
Converts a datetime from US/Eastern (standard or dalyight saving depending on the time) to UTC.
This function is undefined for one hour where it is not possible to infer whether the input datetime is in standard time daylight savings time. This should not be a problem if the times are outside the overlapping hour each year between the two timezones.
- jztools.datetime64.parse_numpy_time_dtype(val: datetime64 | timedelta64) dict#
Returns a dictionary with fields ‘type’ (‘datetime64’ or ‘timedelta64’), ‘num’ (number of date time units) and ‘dt_unit’ (datetime unit, e.g., ‘D’, ‘m’, ‘s’, ‘h’)
- jztools.datetime64.now(res='us', tz: str | tzinfo | None = None)#
- Parameters:
res – A numpy datetime64 specifier, e.g., one of (‘H’, ‘m’, ‘s’, ‘ms’, ‘us’, ‘ns’).