Ticket #8664 (closed defect: fixed)
Opened 2 years ago
Last modified 17 months ago
Timeline calls today yesterday
| Reported by: | Leif Ryge <leif@…> | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.12 |
| Component: | timeline | Version: | 0.11.5 |
| Severity: | major | Keywords: | datetime |
| Cc: | ryano@… | ||
| Release Notes: | |||
| API Changes: | |||
Description
In the hours between UTC midnight and my local (UTC-0700) midnight, the trac timeline calls the current day "yesterday".
All dates and times are correct; it is just the word yesterday that is wrong.
The server's timezone is UTC; my trac account's preferences and my browser are both -0700.
Attachments
Change History
comment:1 Changed 2 years ago by Ryan Ollos <ryano@…>
- Cc ryano@… added
comment:2 Changed 2 years ago by Leif Ryge <leif@…>
comment:3 Changed 2 years ago by cboos
- Milestone set to 0.12
Thanks for the report and the patch.
Yes, I think format_date should not require an extra req.tz argument here.
So instead of:
def format_datetime(t=None, format='%x %X', tzinfo=None): tz = tzinfo or localtz t = to_datetime(t, tzinfo).astimezone(tz)
we should do something like:
def format_datetime(t=None, format='%x %X', tzinfo=None): if tzinfo: tz = tzinfo elif isinstance(t, (date, time, datetime)): tz = t.tzinfo or localtz else: tz = localtz if not isinstance(t, datetime): t = to_datetime(t, tzinfo).astimezone(tz)
(to be tested)
comment:4 Changed 2 years ago by cboos
- Milestone changed from 0.12 to next-minor-0.12.x
comment:5 Changed 21 months ago by rblank
#9386 reported the same issue, and suggested the same patch as comment:2. That patch does resolve the issue, so I applied it in [9799]. I also tested the suggestion in comment:3, but not only does it not solve the issue, but it also mangles displayed times in various locations (e.g. in the date/time preferences). I'm leaving this ticket open to find a correct solution.
comment:6 Changed 21 months ago by cboos
- Milestone changed from next-minor-0.12.x to 0.12.1
- Severity changed from normal to major
I'll take a look.
comment:7 Changed 17 months ago by rblank
The original issue seems to be fixed with [9799], so we could close this against 0.12.
comment:8 Changed 17 months ago by cboos
- Milestone changed from 0.12.1 to 0.12
- Resolution set to fixed
- Status changed from new to closed
Fine by me.



Here is a patch which fixes this. I tested it with my timezone set to -0700 as well as UTC.
--- trac/timeline/web_ui.py.orig 2009-09-14 00:45:31.000000000 +0000 +++ trac/timeline/web_ui.py 2009-09-14 00:45:36.000000000 +0000 @@ -120,8 +120,8 @@ daysback = min(self.max_daysback, daysback) data = {'fromdate': fromdate, 'daysback': daysback, - 'today': format_date(today), - 'yesterday': format_date(today - timedelta(days=1)), + 'today': format_date(today, tzinfo=req.tz), + 'yesterday': format_date(today - timedelta(days=1), tzinfo=req.tz), 'precisedate': precisedate, 'precision': precision, 'events': [], 'filters': [], 'abbreviated_messages': self.abbreviated_messages}This timezone stuff is a bit confusing. It seems like since today = datetime.now(req.tz) it should not be necessary to also pass req.tz to format_date, but apparently it is.