Skip to content

Commit 3a7141e

Browse files
author
Michael Barr
committed
Preparation for release of v0.5.
1 parent 861f48f commit 3a7141e

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Imagine you have the models ``Location`` and ``LocationReportingPeriod``:
9797
)
9898
9999
100-
def _get_reporting_period_timzone(obj):
100+
def _get_reporting_period_timezone(obj):
101101
"""Called as `obj` being the LocationReportingPeriodInstance.
102102
103103
Note:
@@ -117,13 +117,13 @@ Imagine you have the models ``Location`` and ``LocationReportingPeriod``:
117117
verbose_name=_('start'),
118118
# populate_from can also be a string value, provided that the string value
119119
# is a field on the same model
120-
populate_from=_get_reporting_period_timzone,
120+
populate_from=_get_reporting_period_timezone,
121121
# Time override must be a datetime.time instance
122122
time_override=datetime.min.time(),
123123
)
124124
end = LinkedTZDateTimeField(
125125
verbose_name=_('end'),
126-
populate_from=_get_reporting_period_timzone,
126+
populate_from=_get_reporting_period_timezone,
127127
# Time override must be a datetime.time instance
128128
time_override=datetime.max.time(),
129129
)
@@ -253,7 +253,8 @@ Contributors
253253

254254
Changelog
255255
---------
256-
256+
- 0.5 Bug fix: time override on datetime.min.time() failed to set time properly
257+
- 0.4 Removed support for Python 2.5
257258
- 0.3 Code cleanup.
258259
- 0.2 Multiple bug fixes based on testing.
259260
- 0.1 Initial release.

timezone_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = (0, 4)
1+
__version__ = (0, 5)
22
VERSION = '.'.join(map(str, __version__))

timezone_utils/fields.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,20 @@ def pre_save(self, model_instance, add):
207207
# It was a valiant effort. Resistance is futile.
208208
raise
209209

210-
datetime_as_timezone = value.astimezone(tz)
211-
value = tz.normalize(
212-
tz.localize(
213-
datetime.combine(
214-
date=datetime_as_timezone.date(),
215-
time=datetime_as_timezone.time()
210+
# We don't want to double-convert the value. This leads to incorrect
211+
# dates being generated when the overridden time goes back a day.
212+
if self.time_override is None:
213+
datetime_as_timezone = value.astimezone(tz)
214+
value = tz.normalize(
215+
tz.localize(
216+
datetime.combine(
217+
date=datetime_as_timezone.date(),
218+
time=datetime_as_timezone.time()
219+
)
216220
)
217221
)
218-
)
219222

220-
if self.time_override and not (
223+
if self.time_override is not None and not (
221224
self.auto_now or (self.auto_now_add and add)
222225
):
223226
if callable(self.time_override):
@@ -226,7 +229,9 @@ def pre_save(self, model_instance, add):
226229
time_override = self.time_override
227230

228231
if not isinstance(time_override, datetime_time):
229-
raise ValidationError('meh')
232+
raise ValueError(
233+
'Invalid type. Must be a datetime.time instance.'
234+
)
230235

231236
value = tz.normalize(
232237
tz.localize(

0 commit comments

Comments
 (0)