Skip to content
Browse files

-Fix US week numbers

-Fix displaying to many days in a month
  • Loading branch information...
1 parent 7725aa2 commit fd6f7d970f71b3deb889a5a64e0a491b9b86935c Isaac committed Jun 24, 2013
Showing with 16 additions and 6 deletions.
  1. +16 −6 quickcal.py
View
22 quickcal.py
@@ -85,9 +85,17 @@ def __init__(self, day, month, year):
self._get_week()
def _get_week(self):
- iso = not sublime.load_settings("quickcal.sublime-settings").get("sunday_first", True)
+ sunday_first = sublime.load_settings("quickcal.sublime-settings").get("sunday_first", True)
cal_day = datetime.strptime("%d-%d-%d" % (int(self.month), self.day, self.year), "%m-%d-%Y")
- self.week = int(cal_day.strftime("%U")) if not iso else cal_day.isocalendar()[1]
+ week = int(cal_day.strftime("%U")) if sunday_first else cal_day.isocalendar()[1]
+ if sunday_first:
+ first_day = datetime.strptime("%d-%d-%d" % (1, 1, self.year), "%m-%d-%Y")
+ first_week = int(first_day.strftime("%U"))
+ if first_week == 0:
+ week += 1
+ if week > 52:
+ week = 1
+ self.week = week
def __unicode__(self):
return self.str
@@ -220,11 +228,11 @@ def show_calendar_month(self, year, month, day, sunday_first=True, force_update=
start_row = 0
if (num_days + offset) % DAYS_IN_WEEK:
- end_row = (num_days + offset) / DAYS_IN_WEEK
- end_offset = (DAYS_IN_WEEK * (end_row + 1)) - (num_days + offset)
+ end_row = int((num_days + offset) / DAYS_IN_WEEK)
+ end_offset = int((DAYS_IN_WEEK * (end_row + 1)) - (num_days + offset))
else:
- end_row = ((num_days + offset) / DAYS_IN_WEEK) - 1
- end_offset = (DAYS_IN_WEEK * end_row) - (num_days + offset)
+ end_row = int(((num_days + offset) / DAYS_IN_WEEK) - 1)
+ end_offset = int((DAYS_IN_WEEK * end_row) - (num_days + offset))
bfr = self.show_calendar_header()
for r in range(0, int(end_row) + 1):
@@ -243,6 +251,8 @@ def show_calendar_month(self, year, month, day, sunday_first=True, force_update=
empty_cells = (0, 0)
bfr += self.show_calendar_row(start, end, week_no, empty_cells)
week_no += 1
+ if week_no == 53:
+ week_no = 1
bfr += CAL_ROW_BTM_DIV
bfr += self.list_holidays()

0 comments on commit fd6f7d9

Please sign in to comment.
Something went wrong with that request. Please try again.