﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28739	get_fixed_timezone incorrect with negative timedelta	Mike Edmunds	Mike Edmunds	"When called with a ''negative'' datetime.timedelta, django.utils.timezone.get_fixed_timezone instead creates a timezone with a ''positive'' offset 24 hours beyond the negative offset requested:

{{{
>>> import datetime
>>> from django.utils.timezone import get_fixed_timezone
>>> get_fixed_timezone(datetime.timedelta(hours=5)).tzname('')
'+0500'  # correct
>>> get_fixed_timezone(datetime.timedelta(hours=-5)).tzname('')
'+1900'  # expected: '-0500'
}}}

(tzname is just an easy way to see the problem; it accurately reflects the created timezone's offset.)

This has been broken as far back as I've looked; probably everyone uses get_fixed_timezone with integer minutes rather than a timedelta. Patch follows.

**Workaround**

If you encounter this in an older version of Django that won't be patched, there's an easy workaround in your code (on Python 2.7 or later). Change:

{{{
    tz = get_fixed_timezone(delta)  # where delta is a datetime.timedelta object
}}}

to:

{{{
    tz = get_fixed_timezone(delta.total_seconds() // 60)
}}}
"	Bug	closed	Uncategorized	1.8	Normal	fixed			Unreviewed	1	0	0	0	0	0
