Can not set completion date on milestone due to timezone daylight saving
|Reported by:||Owned by:||Remy Blank|
|Cc:||info@…, michaelc@…, jappie@…||Branch:|
If I want to set a completion date for a milestone very close to the actual time, I get the warning message: "Warning: Completion date may not be in the future". For example at '04/27/09 15:30:00' I can not put a completion date of a milestone which is '04/27/09 15:00:00'.
I think this is something closely related to trac's/Python's datetime handling with timezones (the culprit is probably 'trac.util.datefmt.parse_date').
This is my setup:
- Trac 0.11.4 (seeing this with 0.11stable as well)
- Python 2.3 (also checked with Python 2.5)
- pytz is installed
- server timezone (default_timezone in trac.ini) is set to utc
- in the user preferences a different timezone was stored, in that timezone daylight saving is currently active (e.g. Europe/Berlin)
What happens is that parse_date returns a date with the non-dst timezone. Therefore the computed time is off by one hour and compared to UTC it looks like it is a date in the future (because trac only deducts 1h instead of 2h in Europe/Berlin (CEST → GMT+2).
This does not happen if pytz is not installed because trac's timezones don't imply any daylight saving settings.
You can add a workaround for the specific issue if you just remove the check for future days. However this still affects plugin writers.
I think the correct way to deal with this is to use the normalize()/localize() method of a pytz tzinfo object on the generated datetime. I think something like that should be added (branches/0.11-stable/trac/util/datefmt.py#L233):
if not hasattr(tzinfo, 'localize'): # This is a tzinfo define by trac which don't have to deal with dst dt = datetime(*(tm[0:6] + (0, tzinfo))) else: # We need to detect daylight saving correctly - see #... dt = tzinfo.localize(datetime(*tm[0:6]))