Opened 9 years ago
Closed 9 years ago
#12489 closed defect (fixed)
ValueError: year=1899 is before 1900; the datetime strftime() methods require year >= 1900
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.0.12 |
Component: | general | Version: | 1.0.11 |
Severity: | normal | Keywords: | datetime |
Cc: | Branch: | ||
Release Notes: |
Fix |
||
API Changes: | |||
Internal Changes: |
Description
Maybe we can raise a TracError
for this case, or add/or a warning to the timeline page.
2016-05-26 14:42:07,161 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/timeline?from=1900-01-02&daysback=7&authors='">, referrer 'https://bugs.jqueryui.com/' Traceback (most recent call last): File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 562, in _dispatch_request dispatcher.dispatch(req) File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 249, in dispatch resp = chosen_handler.process_request(req) File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/timeline/web_ui.py", line 251, in process_request format='%Y-%m-%d', tzinfo=req.tz) File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 318, in format_date return _format_datetime(t, format, tzinfo, locale, 'date') File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 299, in _format_datetime return _format_datetime_without_babel(t, format) File "/var/www/bugs.jqueryui.com/private/pve/local/lib/python2.7/site-packages/trac/util/datefmt.py", line 246, in _format_datetime_without_babel text = t.strftime(str(format)) ValueError: year=1899 is before 1900; the datetime strftime() methods require year >= 1900
Attachments (0)
Change History (7)
comment:1 by , 9 years ago
Milestone: | → 1.0.12 |
---|---|
Owner: | set to |
Status: | new → assigned |
follow-up: 4 comment:2 by , 9 years ago
I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.
comment:3 by , 9 years ago
We could simply use 'iso8601'
format to solve the original issue.
-
trac/timeline/web_ui.py
diff --git a/trac/timeline/web_ui.py b/trac/timeline/web_ui.py index 15f8c79af..862c36650 100644
a b class TimelineModule(Component): 248 248 previous_start = fromdate.replace(tzinfo=None) - \ 249 249 timedelta(days=daysback + 1) 250 250 previous_start = format_date(to_datetime(previous_start, req.tz), 251 format=' %Y-%m-%d', tzinfo=req.tz)251 format='iso8601', tzinfo=req.tz) 252 252 add_link(req, 'prev', req.href.timeline(from_=previous_start, 253 253 authors=authors, 254 254 daysback=daysback), … … class TimelineModule(Component): 257 257 next_start = fromdate.replace(tzinfo=None) + \ 258 258 timedelta(days=daysback + 1) 259 259 next_start = format_date(to_datetime(next_start, req.tz), 260 format=' %Y-%m-%d', tzinfo=req.tz)260 format='iso8601', tzinfo=req.tz) 261 261 add_link(req, 'next', req.href.timeline(from_=next_start, 262 262 authors=authors, 263 263 daysback=daysback),
follow-up: 6 comment:4 by , 9 years ago
Replying to Jun Omae:
I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.
I noticed that the naive datetime object is immediately converted to a tz-aware datetime object in _format_datetime, which is called by format_date. Therefore to_datetime(next_start, req.tz)
in trac.timeline.web_ui
appears to be redundant.
comment:5 by , 9 years ago
Release Notes: | modified (diff) |
---|
Yeah, comment:3 is the simpler solution. Committed to 1.0-stable in [14810], merged to trunk in [14811]. Added test in [14816,14819], merged to trunk in [14817:14818,14820].
comment:6 by , 9 years ago
Replying to Ryan J Ollos:
Replying to Jun Omae:
I don't agree [3e45f669/rjollos.git] because the change would lead unexpected result if across DST boundary.
I noticed that the naive datetime object is immediately converted to a tz-aware datetime object in _format_datetime, which is called by format_date. Therefore
to_datetime(next_start, req.tz)
intrac.timeline.web_ui
appears to be redundant.
Ok. You're right. I've misunderstood. Please apply it.
comment:7 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Proposed changes in log:rjollos.git:t12489_year_1899.