summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2022-10-12 23:20:32 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-05 05:59:26 +0100
commit41ca2afd1ce49949d509177987c3b4b7c8ba3fa1 (patch)
tree7d878479b3b48df55f2c23527e2444b5e7607149 /django
parentd7a8ab3513dbee10a04e1f7156457b9c83754bf5 (diff)
Simplified django.utils.dateformat.DateFormat.O()/t()/e() a bit.
O() - we should try to avoid calling specifier methods from each other to avoid extra function call overhead. In addition we end up, in this case, duplicating the ambiguous/imaginary datetime checks. We're also going to be looking at simplifying things by having all of these specifier methods return strings and not an random mix of types. t() - the value can only be one of 28, 29, 30, or 31. As such, there is no need to zero-pad to a width of two.
Diffstat (limited to 'django')
-rw-r--r--django/utils/dateformat.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 4b733733f3..adf748b21c 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -93,7 +93,7 @@ class TimeFormat(Formatter):
return ""
try:
- if hasattr(self.data, "tzinfo") and self.data.tzinfo:
+ if getattr(self.data, "tzinfo", None):
return self.data.tzname() or ""
except NotImplementedError:
pass
@@ -139,7 +139,8 @@ class TimeFormat(Formatter):
if self._no_timezone_or_datetime_is_ambiguous_or_imaginary:
return ""
- seconds = self.Z()
+ offset = self.timezone.utcoffset(self.data)
+ seconds = offset.days * 86400 + offset.seconds
sign = "-" if seconds < 0 else "+"
seconds = abs(seconds)
return "%s%02d%02d" % (sign, seconds // 3600, (seconds // 60) % 60)
@@ -293,7 +294,7 @@ class DateFormat(TimeFormat):
def t(self):
"Number of days in the given month; i.e. '28' to '31'"
- return "%02d" % calendar.monthrange(self.data.year, self.data.month)[1]
+ return calendar.monthrange(self.data.year, self.data.month)[1]
def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"