arjuna.tpi.helper.datetime module¶
Arjuna Date Time Helper Classes
Contains many general purpose type abstractions.
- class arjuna.tpi.helper.datetime.DateTime(pydtobj, *, format='%d.%m.%y %H:%M:%S')¶
Bases:
object
Represents a (mutable) date time object.
- Parameters
pydtobj – Python datetime object.
format – String representation. Default is ‘%d.%m.%y %H:%M:%S’.
Note
You can use + and - operators with DateTime and DateTimeDelta objects.
dtobj + dtdelta dtobj - dtdelta
Although reassignment is not necessary, you can also do
dtobj = dtobj + dtdelta dtobj = dtobj - dtdelta
- add(dtdelta)¶
Add a DateTimeDelta object to this object. Modifies current object.
- Parameters
dtdelta – DateTimeDelta Object.
- Returns
This DateTime object (Self)
- as_str(*, format=None)¶
String representation of this DateTime object.
- Keyword Arguments
format – String format to represent the provided date time object. If not provided format set during construction of this object is used.
- classmethod convert(dtstr: str, *, from_format: str = '%d.%m.%y %H:%M:%S', to_format: str = '%d.%m.%y %H:%M:%S')¶
Factory method to create a DateTime object from provided date time string.
- Parameters
dtstr – Date Time string
- Keyword Arguments
from_format – String format to parse the provided date time string. Default is ‘%d.%m.%y %H:%M:%S’.
to_format – String format to create the converted date time string. Default is ‘%d.%m.%y %H:%M:%S’.
- Returns
Date Time string as per to_format
- classmethod from_str(dtstr: str, *, format: str = '%d.%m.%y %H:%M:%S')¶
Factory method to create a DateTime object from provided date time string.
- Parameters
dtstr – Date Time string
- Keyword Arguments
format – String format to parse the provided date time string. Default is ‘%d.%m.%y %H:%M:%S’.
- classmethod now(*, format: str = '%d.%m.%y %H:%M:%S')¶
Factory method to create a DateTime object representing current date and time.
- Keyword Arguments
format – String format to represent the generated date time object. Default is ‘%d.%m.%y %H:%M:%S’.
- stepper(*, delta: Optional[arjuna.tpi.helper.datetime.DateTimeDelta] = None, max_steps: int = 100000, forward: bool = True, format: Optional[str] = None, as_str: bool = True)¶
Factory method to create DateTimeStepper object which takes this DateTime as starting point.
- Keyword Arguments
delta – A DateTimeDelta object used to create next date time object. If not provided, a delta of 1 second is used.
max_steps – Maximum number of steps or iterations of this object. Default is 100000.
forward – Boolean value that sets the direction of date time. If True steps are directed towards future else towards past. Default is True.
format – String format to represent the generated date time object. If not provided, it is taken from this DateTime object.
as_str – Boolean value that controls the return type on next calls. If True, the iterable returns the data time object as a string else DateTime object is returned. Default is True.
- sub(dtdelta)¶
Add a DateTimeDelta object to this object. Modifies current object.
- Parameters
dtdelta – DateTimeDelta Object.
- Returns
This DateTime object (Self)
- class arjuna.tpi.helper.datetime.DateTimeDelta(*, weeks: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0, milliseconds: int = 0, microseconds: int = 0)¶
Bases:
object
Represents a delta (difference) in date time.
- Keyword Arguments
weeks – Delta number of weeks.
days – Delta number of days.
hours – Delta number of hours.
minutes – Delta number of minutes.
seconds – Delta number of seconds.
miliseconds – Delta number of miliseconds.
microseconds – Delta number of microseconds.
- classmethod builder()¶
Create a DateTimeDeltaBuilder object.
- Returns
DateTimeDeltaBuilder object
- from_now(*, forward: bool = True, format: str = '%d.%m.%y %H:%M:%S')¶
- Keyword Arguments
forward – Boolen value that sets the direction of date time. If True delta is added else it is subtracted. Default is True.
format – String format to represent the generated date time object. Default is ‘%d.%m.%y %H:%M:%S’.
- classmethod zero()¶
Create a DateTimeDelta object which represents no change in date time.
- Returns
DateTimeDelta object.
- class arjuna.tpi.helper.datetime.DateTimeDeltaBuilder¶
Bases:
object
Builder class to flexibly build a DateTimeDelta object.
- build()¶
Build a DateTimeDelta object as per values set in builder.
- Returns
DateTimeDelta object.
- days(count: int)¶
Set number of detla days.
- Parameters
count – Number of days
- hours(count: int)¶
Set number of detla hours.
- Parameters
count – Number of hours
- microseconds(count: int)¶
Set number of detla microseconds.
- Parameters
count – Number of microseconds
- milliseconds(count: int)¶
Set number of detla miliseconds.
- Parameters
count – Number of milliseconds
- minutes(count: int)¶
Set number of detla minutes.
- Parameters
count – Number of minutes
- seconds(count: int)¶
Set number of detla seconds.
- Parameters
count – Number of seconds
- weeks(count: int)¶
Set number of detla weeks.
- Parameters
count – Number of weeks
- class arjuna.tpi.helper.datetime.DateTimeStepper(*, start: Optional[arjuna.tpi.helper.datetime.DateTime] = None, delta: Optional[arjuna.tpi.helper.datetime.DateTimeDelta] = None, max_steps: int = 100000, forward: bool = True, format: Optional[str] = None, as_str: bool = True)¶
Bases:
object
An iterable object that returns DateTime objects or strings as per provided arguments.
- Keyword Arguments
start – Arjuna DateTime object to start stepping. If not supplied current date & time is used. Returned as first value.
delta – A DateTimeDelta object used to create next date time object. If not provided, a delta of 1 second is used.
max_steps – Maximum number of steps or iterations of this object. Default is 100000.
forward – Boolen value that sets the direction of date time. If True steps are directed towards future else towards past. Default is True.
format – String format to represent the generated date time object. If not provided, it is taken from start argument. If start argument is not provided it defaults to ‘%d.%m.%y %H:%M:%S’.
as_str – Boolena value that controls the return type on next calls. If True, the iterable returns the data time object as a string else DateTime object is returned. Default is True.
Note
You can make next() call to get next DateTime object or string:
dtstepperDateTimeStepper() dt = dtstepper.next()
If you have explcitly set max_steps, a better usage pattern is to use this object in a Python for loop:
for dt in DateTimeStepper(max_steps=25): # Do something print(dt)
- next()¶
Returns next DateTime object or string.
- class arjuna.tpi.helper.datetime.Time(time_unit, value)¶
Bases:
object
A time object.
- Parameters
time_unit – TimeUnit enum value.
value – An integer representing this time value.
- classmethod milliseconds(value)¶
Factory method to a create a Time object for milliseconds.
- Parameters
value – Number of milliseconds
- classmethod minutes(value)¶
Factory method to a create a Time object for minutes.
- Parameters
value – Number of minutes
- classmethod seconds(value)¶
Factory method to a create a Time object for seconds.
- Parameters
value – Number of seconds