Commits

Yuji Hanamura committed 6f169a2

Added the error check to WeekDb.__init_db.
Fixed the bug of end of year.
Support USA numbering of week number, and default is set to USA numbering.

Comments (0)

Files changed (1)

         if isinstance(year, basestring):
             year = int(year)
 
+        if not isinstance(year, int):
+            raise TypeError('year must be integers or str that contains only numbers')
+
         start_day = datetime.date(year, 1, 1)
-        stop_day = datetime.date(year, 12, 31)
+        stop_day = datetime.date(year + 1, 1, 1)
 
         week_db = {}
         for x in range(0, (stop_day - start_day).days):
         return cmp(self.__year, other.__year)
 
 
-def get_week_num(date=None):
+def get_week_num(date=None, iso=False):
 
     if not date:
         date = datetime.date.today()
     elif not isinstance(date, datetime.date):
         date = datetime.date(int(date.year), int(date.month), int(date.year))
 
-    return date.isocalendar()[1]
+    if iso:
+        return date.isocalendar()[1]
+    else:
+        return int(date.strftime('%U'))
 
 
 if __name__ == '__main__':