summaryrefslogtreecommitdiff
path: root/tropical/calstate.py
diff options
context:
space:
mode:
authorLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 12:25:41 +0200
committerLoïc Guégan <loic.guegan@mailbox.org>2024-09-16 12:25:41 +0200
commit79ce6bc894120527729bb282773a77a3c9cbaa2b (patch)
tree2ca8590a99d5f43f4838acd3b3abb5b5d98ddeed /tropical/calstate.py
Minor changes
Diffstat (limited to 'tropical/calstate.py')
-rw-r--r--tropical/calstate.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tropical/calstate.py b/tropical/calstate.py
new file mode 100644
index 0000000..2a760a6
--- /dev/null
+++ b/tropical/calstate.py
@@ -0,0 +1,49 @@
+
+import calendar
+from datetime import date, timedelta
+
+class CalState:
+
+ def __init__(self):
+ self.gotoToday()
+ self.firstWeekDay=0
+
+ def setFirstWeekDay(self, i):
+ self.firstWeekDay=i
+
+ def goto(self, year, month, day):
+ self.year=year
+ self.month=month
+ self.day=day
+
+ def gotoToday(self):
+ today = date.today()
+ self.goto(today.year, today.month, today.day)
+
+ def gotoNextWeek(self):
+ day=date(self.year,self.month,self.day) + timedelta(weeks=1)
+ self.goto(day.year,day.month, day.day)
+
+ def gotoPrevWeek(self):
+ day=date(self.year,self.month,self.day) - timedelta(weeks=1)
+ self.goto(day.year,day.month, day.day)
+
+ def getMonthDays(self):
+ cal=calendar.Calendar()
+ days=list()
+ for day in cal.itermonthdays4(self.year, self.month):
+ days.append(day)
+ return days
+
+ def getWeekDays(self):
+ daysMonth=self.getMonthDays()
+ daysWeek=list()
+ for year, month, day, count in daysMonth:
+ daysWeek.append((year,month,day,count))
+ if len(daysWeek) >= 7:
+ # Check if day within the week
+ for yy, mm, dd, cc in daysWeek:
+ if (yy, mm, dd) == (self.year, self.month, self.day):
+ return daysWeek
+ daysWeek.clear()
+ return None