diff options
Diffstat (limited to 'tropical/calstate.py')
| -rw-r--r-- | tropical/calstate.py | 49 |
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 |
