summaryrefslogtreecommitdiff
path: root/calendar_entry.py
diff options
context:
space:
mode:
Diffstat (limited to 'calendar_entry.py')
-rw-r--r--calendar_entry.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/calendar_entry.py b/calendar_entry.py
new file mode 100644
index 0000000..1066f8d
--- /dev/null
+++ b/calendar_entry.py
@@ -0,0 +1,59 @@
+# calendar_entry.py
+import uuid
+from datetime import datetime
+
+class CalendarEntry:
+ """Represents a single calendar entry with all its properties"""
+
+ def __init__(self, start_date, end_date, keyword, entry_id=None,
+ corrected_start_date=None, corrected_end_date=None,
+ time_period=None, commentary: str = ""):
+ self.id = entry_id if entry_id else str(uuid.uuid4())
+
+ # Convert string dates to datetime if necessary
+ self.start_date = (
+ datetime.fromisoformat(start_date)
+ if isinstance(start_date, str)
+ else start_date
+ )
+ self.end_date = (
+ datetime.fromisoformat(end_date)
+ if isinstance(end_date, str)
+ else end_date
+ )
+
+ self.keyword = keyword
+ self.corrected_start_date = corrected_start_date
+ self.corrected_end_date = corrected_end_date
+ self.time_period = time_period
+ self.commentary = commentary
+
+ def to_dict(self):
+ """Convert entry to dictionary for serialization"""
+ return {
+ 'id': self.id,
+ 'start_date': self.start_date.isoformat(),
+ 'end_date': self.end_date.isoformat(),
+ 'keyword': self.keyword,
+ 'corrected_start_date': self.corrected_start_date.isoformat() if self.corrected_start_date else None,
+ 'corrected_end_date': self.corrected_end_date.isoformat() if self.corrected_end_date else None,
+ 'commentary': self.commentary,
+ }
+
+ @classmethod
+ def from_dict(cls, data):
+ """Create entry from dictionary"""
+ return cls(
+ start_date=datetime.fromisoformat(data['start_date']),
+ end_date=datetime.fromisoformat(data['end_date']),
+ keyword=data['keyword'],
+ entry_id=data['id'],
+ corrected_start_date=datetime.fromisoformat(data['corrected_start_date']) if data.get('corrected_start_date') else None,
+ corrected_end_date=datetime.fromisoformat(data['corrected_end_date']) if data.get('corrected_end_date') else None,
+ commentary=data.get('commentary', ""),
+ )
+
+ def __repr__(self):
+ return (f"CalendarEntry(id={self.id}, start_date={self.start_date}, "
+ f"end_date={self.end_date}, keyword='{self.keyword}', "
+ f"corrected_start_date={self.corrected_start_date}, corrected_end_date={self.corrected_end_date})")