summaryrefslogtreecommitdiffstats
path: root/Lib/calendar.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2006-04-01 20:40:23 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2006-04-01 20:40:23 (GMT)
commitf878b8120c89d53722ba77c5f29c680695fd4257 (patch)
tree5dcaf740f87a325bcb0a788d15eacce33e9f42d7 /Lib/calendar.py
parentcd10347b65377f62073c9fccbbdbf393823c1bbd (diff)
downloadcpython-f878b8120c89d53722ba77c5f29c680695fd4257.zip
cpython-f878b8120c89d53722ba77c5f29c680695fd4257.tar.gz
cpython-f878b8120c89d53722ba77c5f29c680695fd4257.tar.bz2
Make firstweekday a simple attribute instead
of hiding it behind a setter and a getter.
Diffstat (limited to 'Lib/calendar.py')
-rw-r--r--Lib/calendar.py29
1 files changed, 12 insertions, 17 deletions
diff --git a/Lib/calendar.py b/Lib/calendar.py
index a003b46..41537ba 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -128,25 +128,14 @@ class Calendar(object):
"""
def __init__(self, firstweekday=0):
- self._firstweekday = firstweekday # 0 = Monday, 6 = Sunday
-
- def firstweekday(self):
- return self._firstweekday
-
- def setfirstweekday(self, weekday):
- """
- Set weekday (Monday=0, Sunday=6) to start each week.
- """
- if not MONDAY <= weekday <= SUNDAY:
- raise IllegalWeekdayError(weekday)
- self._firstweekday = weekday
+ self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday
def iterweekdays(self):
"""
Return a iterator for one week of weekday numbers starting with the
configured first one.
"""
- for i in xrange(self._firstweekday, self._firstweekday + 7):
+ for i in xrange(self.firstweekday, self.firstweekday + 7):
yield i%7
def itermonthdates(self, year, month):
@@ -157,13 +146,13 @@ class Calendar(object):
"""
date = datetime.date(year, month, 1)
# Go back to the beginning of the week
- days = (date.weekday() - self._firstweekday) % 7
+ days = (date.weekday() - self.firstweekday) % 7
date -= datetime.timedelta(days=days)
oneday = datetime.timedelta(days=1)
while True:
yield date
date += oneday
- if date.month != month and date.weekday() == self._firstweekday:
+ if date.month != month and date.weekday() == self.firstweekday:
break
def itermonthdays2(self, year, month):
@@ -570,8 +559,14 @@ class LocaleHTMLCalendar(HTMLCalendar):
# Support for old module level interface
c = TextCalendar()
-firstweekday = c.firstweekday
-setfirstweekday = c.setfirstweekday
+def firstweekday():
+ return c.firstweekday
+
+def setfirstweekday(firstweekday):
+ if not MONDAY <= firstweekday <= SUNDAY:
+ raise IllegalWeekdayError(firstweekday)
+ c.firstweekday = firstweekday
+
monthcalendar = c.monthdayscalendar
prweek = c.prweek
week = c.formatweek