added: further needed vars and methods
This commit is contained in:
parent
caf4634724
commit
c75d3cecd9
109
day.py
109
day.py
@ -1,41 +1,112 @@
|
|||||||
''' Dayclass wich represents a day at work '''
|
''' Contains dayclas as representation of a day at work '''
|
||||||
|
|
||||||
from calculation import hoursSpent
|
from calculation import hoursSpent
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
|
|
||||||
class Day:
|
class Day:
|
||||||
|
'''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!
|
||||||
|
'''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.begin = 0
|
|
||||||
self.end = 0
|
self.date: str = datetime.now().date()
|
||||||
self.begin_break = 0
|
|
||||||
self.end_break = 0
|
self.begin: datetime = datetime.__init__
|
||||||
self.duration = 0
|
|
||||||
|
self.end: datetime = datetime.__init__
|
||||||
|
|
||||||
|
self.begin_break: datetime = datetime.__init__
|
||||||
|
|
||||||
|
self.end_break: datetime = datetime.__init__
|
||||||
|
|
||||||
|
self.duration: datetime = datetime.__init__
|
||||||
|
|
||||||
|
self.isDayStarted: bool = False
|
||||||
|
self.isBreakDone: bool = False
|
||||||
|
self.isInBreak: bool = False
|
||||||
|
|
||||||
def beginDay(self):
|
def beginDay(self):
|
||||||
|
'''Saves the time where a new day was started.'''
|
||||||
self.begin = datetime.now()
|
self.begin = datetime.now()
|
||||||
print(self.begin)
|
self.isDayStarted = True
|
||||||
|
|
||||||
def make_break(self):
|
def make_break(self):
|
||||||
self.begin_break = datetime.now()
|
'''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")
|
||||||
|
|
||||||
|
self.beingin_break = datetime.now()
|
||||||
|
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")
|
||||||
|
|
||||||
def go_on(self):
|
|
||||||
self.end_break = datetime.now()
|
self.end_break = datetime.now()
|
||||||
|
self.isInBreak = False
|
||||||
|
self.isBreakDone = True
|
||||||
|
|
||||||
def endDay(self):
|
def endDay(self):
|
||||||
|
'''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")
|
||||||
|
|
||||||
self.end = datetime.now()
|
self.end = datetime.now()
|
||||||
self.duration = hoursSpent(
|
self.duration = hoursSpent(
|
||||||
self.begin, self.end, self.begin_break, self.end_break)
|
self.begin, self.end, self.begin_break, self.end_break)
|
||||||
|
|
||||||
|
def get_date(self) -> str:
|
||||||
|
''' Returns the date of the day'''
|
||||||
|
return self.date
|
||||||
|
|
||||||
first_day = Day()
|
def is_day_started(self) -> bool:
|
||||||
first_day.beginDay()
|
return self.isDayStarted
|
||||||
sleep(1)
|
|
||||||
first_day.make_break()
|
def is_break_done(self) -> bool:
|
||||||
sleep(2)
|
return self.isBreakDone
|
||||||
first_day.go_on()
|
|
||||||
sleep(10)
|
def is_in_break(self) -> bool:
|
||||||
first_day.endDay()
|
return self.isInBreak
|
||||||
print("worked", first_day.duration)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user