adding definition for timespans for ls and acc command
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import re
|
||||
|
||||
from datetime import date, datetime, timedelta
|
||||
from model.DataStore import DataStore
|
||||
from model.TimeSlot import TimeSlot
|
||||
@@ -16,9 +14,10 @@ class TimeSlotContainer:
|
||||
def get_all_time_slots(self) -> list[TimeSlot]:
|
||||
return self._ds.get_all_time_slots()
|
||||
|
||||
def get_time_slots_by_date(self, d: date = datetime.now().date()):
|
||||
def get_time_slots_by_date(self, start: date, end: date = datetime.now().date()):
|
||||
# The selection will be oriented at the start date
|
||||
return [ts for ts in self._ds.get_all_time_slots()
|
||||
if ts.start.date() == datetime.now().date()]
|
||||
if ts.start >= start and ts.start <= end]
|
||||
|
||||
def open_time_slot(self, name: str, start_dt: datetime = datetime.now()):
|
||||
if len(self.get_open_time_slots()) > 0:
|
||||
@@ -45,10 +44,6 @@ class TimeSlotContainer:
|
||||
def delete_time_slot(self, ts: TimeSlot):
|
||||
raise NotImplementedError
|
||||
|
||||
def accumulate_duration(self, query: str) -> timedelta:
|
||||
pattern = re.compile(query)
|
||||
return sum([ts.duration() for ts in self._ds.get_all_time_slots()
|
||||
if pattern.search(ts.name) ], start=timedelta(0))
|
||||
|
||||
try:
|
||||
time_slot_container = TimeSlotContainer(DataStore("data.json"))
|
||||
|
||||
Reference in New Issue
Block a user