summaryrefslogtreecommitdiff
path: root/django/utils/dateformat.py
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2019-11-15 17:30:22 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-18 11:30:23 +0100
commit5e2839f3207a02c05b96d761b2441d1ef4d920d4 (patch)
tree65de71bf49a410673663be53f93425b08da04fb2 /django/utils/dateformat.py
parent1185c6172b4dd5482b7bc76b12d7a0588320e027 (diff)
Simplified DateFormat.W() and z().
Diffstat (limited to 'django/utils/dateformat.py')
-rw-r--r--django/utils/dateformat.py30
1 files changed, 2 insertions, 28 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index af46a81ce6..82cb444691 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -208,8 +208,6 @@ class TimeFormat(Formatter):
class DateFormat(TimeFormat):
- year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
-
def b(self):
"Month, textual, 3 letters, lowercase; e.g. 'jan'"
return MONTHS_3[self.data.month]
@@ -316,28 +314,7 @@ class DateFormat(TimeFormat):
def W(self):
"ISO-8601 week number of year, weeks starting on Monday"
- # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
- jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
- weekday = self.data.weekday() + 1
- day_of_year = self.z()
- if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
- if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year - 1)):
- week_number = 53
- else:
- week_number = 52
- else:
- if calendar.isleap(self.data.year):
- i = 366
- else:
- i = 365
- if (i - day_of_year) < (4 - weekday):
- week_number = 1
- else:
- j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
- week_number = j // 7
- if jan1_weekday > 4:
- week_number -= 1
- return week_number
+ return self.data.isocalendar()[1]
def y(self):
"Year, 2 digits; e.g. '99'"
@@ -349,10 +326,7 @@ class DateFormat(TimeFormat):
def z(self):
"""Day of the year, i.e. 1 to 366."""
- doy = self.year_days[self.data.month] + self.data.day
- if self.L() and self.data.month > 2:
- doy += 1
- return doy
+ return self.data.timetuple().tm_yday
def format(value, format_string):