Datetime API#
Parsers#
dt
#
td
#
- ptr.datetime.td(delta) datetime.timedelta [source]#
Time delta parser.
Example:
7 day, 12:34:56.789
for 7 days, 12 hours, 34 minutes, 56 secondes and 789 milliseconds.We recommend to use this formatting but you can provide explicit units following the rules below:
Valid units:
ms
,msec
,millisecond
s
,sec
,second
m
,min
,minute
h
,hr
,hour
d
,D
,day
Plural units are also valid.
Space between the value and the units is accepted.
Month(s) and year(s) are not accepted.
If a
int
or afloat
is provide, it is assume that the value is express in secondes.- Raises
ValueError – If the provided value format is invalid.
Elements#
Time
#
StartTime
#
- class ptr.datetime.StartTime(time, description=None)[source]#
Bases:
ptr.datetime.time.ElementTime
PTR start ElementTime element.
- Parameters
time (str, datetime.datetime or numpy.datetime64) – Element start time.
description (str or list, optional) – Element description, put as a xml-comment on top of the element.
EndTime
#
- class ptr.datetime.EndTime(time, description=None)[source]#
Bases:
ptr.datetime.time.ElementTime
PTR end time element.
- Parameters
time (str, datetime.datetime or numpy.datetime64) – Element end time.
description (str or list, optional) – Element description, put as a xml-comment on top of the element.
ElementTime
#
- class ptr.datetime.time.ElementTime(tag, time, description=None)[source]#
Bases:
ptr.datetime.time.WithTime
,ptr.element.Element
Time element.
- Parameters
tag (str) – Element tag name.
time (str, datetime.datetime or numpy.datetime64) – Element time.
description (str or list, optional) – Element description, put as a xml-comment on top of the element.
Note
The element is parsed as a native datetime.datetime object, and display in XML in ISO format:
YYYY-MM-DDThh:mm:ss
.- property datetime: datetime.datetime#
Datetime value.
WithTime
#
ElementWindow
#
- class ptr.datetime.window.ElementWindow(tag, start, end, *elements, **attrs)[source]#
Bases:
ptr.element.Element
,ptr.datetime.window.WithDatetimeWindow
Element with datetime window properties.
WithDatetimeWindow
#
- class ptr.datetime.window.WithDatetimeWindow[source]#
Bases:
object
Add Time window properties to Element objects.
- property start: ptr.datetime.time.StartTime#
Time window start time value.
- property end: ptr.datetime.time.EndTime#
Time window end time value.
- property window#
Time window start and end time values.
- property duration#
Block duration.
- edit(*, start=None, end=None)[source]#
Edit temporal window boundaries.
- Parameters
start (str, datetime.datetime or datetime.timedelta) – Start time absolute or relative offset.
end (str, datetime.datetime or datetime.timedelta) – End time absolute or relative offset.
- Raises
ValueError – If the new start time is after the end time.
ValueError – If the new end time is before the start time.
Warning
This operation change the duration of the temporal window.
- offset(offset, *, ref='start')[source]#
Offset the temporal window globally.
- Parameters
offset (str datetime.timedelta or datetime.datetime) – Global or relative offset.
ref (str, optional) – Boundary reference for relative offset. Only
start|end|center
are accepted
- Raises
KeyError – If the reference keyword is invalid.
Note
This operation does not change the duration of the window.
- split(time, *, gap=None, ref='start')[source]#
Split the temporal window in two windows.
- Parameters
time (str or datetime.datetime) – Splitting datetime.
gap (str, optional) – Time delta gap between the windows.
ref (str, optional) – Reference location of the gap with respect to provided time. Only
start|end|center
are accepted
- Returns
Two copy of the original element in each time window.
- Return type
- Raises
KeyError – If the reference keyword is invalid.
ValueError – If the gap is too large for the window.
Warning
This operation change the duration of the temporal window.