Utility class to handle time representation for Chore Start Time
Parameters:
| Name |
Type |
Description |
Default |
year
|
int
|
|
required
|
month
|
int
|
|
required
|
day
|
int
|
|
required
|
hour
|
int
|
|
required
|
minute
|
int
|
|
required
|
second
|
int
|
|
required
|
Source code in TM1py/Objects/ChoreStartTime.py
| def __init__(self, year: int, month: int, day: int, hour: int, minute: int, second: int, tz: str = None):
"""
:param year: year
:param month: month
:param day: day
:param hour: hour or None
:param minute: minute or None
:param second: second or None
"""
self._datetime = datetime.datetime.combine(datetime.date(year, month, day), datetime.time(hour, minute, second))
self.tz = tz
|
start_time_string
property
tz = tz
instance-attribute
__str__()
Source code in TM1py/Objects/ChoreStartTime.py
| def __str__(self):
return self.start_time_string
|
add(days=0, hours=0, minutes=0, seconds=0)
Source code in TM1py/Objects/ChoreStartTime.py
| def add(self, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0):
self._datetime = self._datetime + datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
|
from_string(start_time_string)
classmethod
Source code in TM1py/Objects/ChoreStartTime.py
| @classmethod
def from_string(cls, start_time_string: str) -> "ChoreStartTime":
# extract optional tz info (e.g., +01:00) from string end
if "+" in start_time_string:
# case "2020-11-05T08:00:01+01:00",
tz = "+" + start_time_string.split("+")[1]
elif start_time_string.count("-") == 3:
# case: "2020-11-05T08:00:01-01:00",
tz = "-" + start_time_string.split("-")[-1]
else:
tz = None
# f to handle strange timestamp 2016-09-25T20:25Z instead of common 2016-09-25T20:25:00Z
# second is defaulted to 0 if not specified in the chore schedule
def format_time(value: int) -> str:
return int(value or 0)
return cls(
year=format_time(start_time_string[0:4]),
month=format_time(start_time_string[5:7]),
day=format_time(start_time_string[8:10]),
hour=format_time(start_time_string[11:13]),
minute=format_time(start_time_string[14:16]),
second=format_time(0 if start_time_string[16] != ":" else start_time_string[17:19]),
tz=tz,
)
|
set_time(year=None, month=None, day=None, hour=None, minute=None, second=None)
Source code in TM1py/Objects/ChoreStartTime.py
| def set_time(
self,
year: int = None,
month: int = None,
day: int = None,
hour: int = None,
minute: int = None,
second: int = None,
):
_year = year if year is not None else self._datetime.year
_month = month if month is not None else self._datetime.month
_day = day if day is not None else self._datetime.day
_hour = hour if hour is not None else self._datetime.hour
_minute = minute if minute is not None else self._datetime.minute
_second = second if second is not None else self._datetime.second
self._datetime = self._datetime.replace(
year=_year, month=_month, day=_day, hour=_hour, minute=_minute, second=_second
)
|
subtract(days=0, hours=0, minutes=0, seconds=0)
Source code in TM1py/Objects/ChoreStartTime.py
| def subtract(self, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0):
self._datetime = self._datetime - datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
|