enhance get_hours_present

master
Maximilian Zettler 4 years ago
parent 9037a0f91c
commit 0885bf300a
  1. 10
      timebot/constants.py
  2. 25
      timebot/timebot.py

@ -15,13 +15,13 @@ class DateFormats(Enum):
SIMPLE_DATE = "%Y-%m-%d" SIMPLE_DATE = "%Y-%m-%d"
SIMPLE_TIME = "%H:%M" SIMPLE_TIME = "%H:%M"
"""
Return escaped version of value if value is string.
"%" will be escaped -> "%%"
"""
@DynamicClassAttribute @DynamicClassAttribute
def evalue(self): def evalue(self):
"""
Return escaped version of value if value is string.
"%" will be escaped -> "%%"
"""
if isinstance(self._value_, (str,)): if isinstance(self._value_, (str,)):
return self._value_.replace("%", "%%") return self._value_.replace("%", "%%")
return self._value_ return self._value_

@ -363,5 +363,28 @@ class TimeBot:
start_date=now.replace(hour=0, minute=0, second=0, microsecond=0), start_date=now.replace(hour=0, minute=0, second=0, microsecond=0),
end_date=now.replace(hour=0, minute=0, second=0, microsecond=0), end_date=now.replace(hour=0, minute=0, second=0, microsecond=0),
) )
time_delta = now - datetime.datetime.strptime(punches[-1]["dateTime"], DateFormats.FULL_DATETIME.value) punch_out_time = now
if punches and punches[0]["entryNumber"] == PunchCodes.LEAVING.value:
punch_out_time = datetime.datetime.strptime(punches.pop(0)["dateTime"], DateFormats.FULL_DATETIME.value)
punch_in_time = None
if punches and punches[-1]["entryNumber"] == PunchCodes.COMING.value:
punch_in_time = datetime.datetime.strptime(punches.pop(-1)["dateTime"], DateFormats.FULL_DATETIME.value)
if punch_in_time is None:
return datetime.timedelta(seconds=0)
breaks = []
end = now
for i in punches:
if i["entryNumber"] == PunchCodes.BREAK_END.value:
end = datetime.datetime.strptime(i["dateTime"], DateFormats.FULL_DATETIME.value)
if i["entryNumber"] == PunchCodes.BREAK_START.value:
start = datetime.datetime.strptime(i["dateTime"], DateFormats.FULL_DATETIME.value)
breaks.append(end - start)
end = now
time_delta = punch_out_time - punch_in_time
for i in breaks:
time_delta = time_delta - i
return time_delta return time_delta

Loading…
Cancel
Save