2019-05-30 15:01:12 +02:00
|
|
|
''' Contains dayclas as representation of a day at work '''
|
2019-05-30 12:16:33 +02:00
|
|
|
|
|
|
|
from calculation import hoursSpent
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
class Day:
|
2019-05-30 15:01:12 +02:00
|
|
|
'''A class used to represent a day at work
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
----------
|
|
|
|
|
|
|
|
date: str
|
|
|
|
date of the day set at init
|
|
|
|
|
|
|
|
begin: datetime
|
|
|
|
datetime timestamp at started day, starting day and initializing day are seperate
|
|
|
|
|
|
|
|
end: dateime
|
|
|
|
dateime timestamp at end of a day
|
|
|
|
|
|
|
|
begin_break: datetime
|
|
|
|
dateime timestamp at begin of a break
|
|
|
|
|
|
|
|
end_break: datetime
|
|
|
|
dateime timestamp at end of a break
|
|
|
|
|
|
|
|
duration: dateime
|
|
|
|
dateime of working duration - pause
|
|
|
|
|
|
|
|
isDayStarted: bool
|
|
|
|
|
|
|
|
isBreakDone: bool
|
|
|
|
|
|
|
|
isInBreak: bool
|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
|
|
|
The Day class holds only one pause!
|
|
|
|
'''
|
2019-05-30 12:16:33 +02:00
|
|
|
|
|
|
|
def __init__(self):
|
2019-05-30 15:01:12 +02:00
|
|
|
|
|
|
|
self.date: str = datetime.now().date()
|
|
|
|
|
2019-05-30 16:12:51 +02:00
|
|
|
self.begin = 0
|
|
|
|
self.end = 0
|
|
|
|
self.begin_break = 0
|
|
|
|
self.end_break = 0
|
|
|
|
self.duration = 0
|
2019-05-30 15:01:12 +02:00
|
|
|
|
|
|
|
self.isDayStarted: bool = False
|
|
|
|
self.isBreakDone: bool = False
|
|
|
|
self.isInBreak: bool = False
|
2019-05-30 12:16:33 +02:00
|
|
|
|
|
|
|
def beginDay(self):
|
2019-05-30 15:01:12 +02:00
|
|
|
'''Saves the time where a new day was started.'''
|
2019-05-30 16:12:51 +02:00
|
|
|
self.begin_break = datetime.now()
|
2019-05-30 15:01:12 +02:00
|
|
|
self.isDayStarted = True
|
2019-05-30 12:16:33 +02:00
|
|
|
|
2019-05-30 12:49:27 +02:00
|
|
|
def make_break(self):
|
2019-05-30 15:01:12 +02:00
|
|
|
'''Saves the time where a break was started'''
|
|
|
|
if not self.isDayStarted:
|
|
|
|
raise AssertionError("Day hasn't been started yet")
|
|
|
|
if self.isBreakDone or self.isInBreak:
|
|
|
|
raise AssertionError(
|
|
|
|
"You are already in break or have done your break already")
|
|
|
|
|
2019-05-30 16:12:51 +02:00
|
|
|
self.begin = datetime.now()
|
2019-05-30 15:01:12 +02:00
|
|
|
self.isInBreak = True
|
|
|
|
|
|
|
|
def stop_break(self):
|
|
|
|
'''Saves the time where the break was finished'''
|
|
|
|
if not self.isDayStarted:
|
|
|
|
raise AssertionError("Day hasn't been started yet")
|
|
|
|
if not self.isInBreak:
|
|
|
|
raise AssertionError(
|
|
|
|
"You didn't start breaking yet")
|
2019-05-30 12:49:27 +02:00
|
|
|
|
|
|
|
self.end_break = datetime.now()
|
2019-05-30 15:01:12 +02:00
|
|
|
self.isInBreak = False
|
|
|
|
self.isBreakDone = True
|
2019-05-30 12:49:27 +02:00
|
|
|
|
2019-05-30 12:16:33 +02:00
|
|
|
def endDay(self):
|
2019-05-30 15:01:12 +02:00
|
|
|
'''Saves the time where the work was ended and calcuclats the duration of work done'''
|
|
|
|
if not self.isDayStarted:
|
|
|
|
raise AssertionError("Day hasn't been started yet")
|
|
|
|
|
2019-05-30 12:16:33 +02:00
|
|
|
self.end = datetime.now()
|
2019-05-30 12:49:27 +02:00
|
|
|
self.duration = hoursSpent(
|
|
|
|
self.begin, self.end, self.begin_break, self.end_break)
|
|
|
|
|
2019-05-30 15:01:12 +02:00
|
|
|
def get_date(self) -> str:
|
|
|
|
''' Returns the date of the day'''
|
|
|
|
return self.date
|
|
|
|
|
|
|
|
def is_day_started(self) -> bool:
|
|
|
|
return self.isDayStarted
|
|
|
|
|
|
|
|
def is_break_done(self) -> bool:
|
|
|
|
return self.isBreakDone
|
2019-05-30 12:49:27 +02:00
|
|
|
|
2019-05-30 15:01:12 +02:00
|
|
|
def is_in_break(self) -> bool:
|
|
|
|
return self.isInBreak
|