Skip to content

Commit fcb2db9

Browse files
Updated documentation to add missed choices for grouped choices. Fixed a bug for time_override. Version bump for preparation of v0.8 release.
1 parent 2bdf78b commit fcb2db9

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Contributors
107107

108108
Changelog
109109
---------
110+
- 0.8 Corrected a bug to where ``time_override`` caused invalid date due to not converting to the correct timezone first. Added choices ``GROUPED_ALL_TIMEZONES_CHOICES`` and ``GROUPED_COMMON_TIMEZONES_CHOICES`` to the documentation.
110111
- 0.7 Corrected a bug where datetime.max.time() resulted in incorrect date/time. Changed tests to compare time_override models via string to prevent future regressions. Added choices ``GROUPED_ALL_TIMEZONES_CHOICES`` and ``GROUPED_COMMON_TIMEZONES_CHOICES``.
111112
- 0.6 Added RTD documentation. LinkedTZDateTimeField now returns the datetime object in the overidden timezone and time.
112113
- 0.5 Bug fix: time override on datetime.min.time() failed to set time properly

docs/choices.rst

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,78 @@ Contains constants and functions to generate model/form choices for time zones.
5757
...
5858
)
5959
60+
``GROUPED_ALL_TIMEZONES_CHOICES``
61+
---------------------------------
62+
.. py:data:: GROUPED_ALL_TIMEZONES_CHOICES
63+
64+
Returns choices grouped by the timezone offset and ordered alphabetically by
65+
their Olson Time Zone name populated from |pytz.all_timezones|_.
66+
67+
.. code-block:: python
68+
69+
>>> from timezone_utils.choices import GROUPED_ALL_TIMEZONES_CHOICES
70+
>>> print GROUPED_ALL_TIMEZONES_CHOICES
71+
(
72+
(
73+
'GMT-12:00',
74+
(
75+
('Etc/GMT+12', 'Etc/GMT+12'),
76+
)
77+
),
78+
(
79+
'GMT-11:00',
80+
(
81+
('Etc/GMT+11', 'Etc/GMT+11'),
82+
('Pacific/Midway', 'Pacific/Midway'),
83+
('Pacific/Niue', 'Pacific/Niue'),
84+
('Pacific/Pago_Pago', 'Pacific/Pago_Pago'),
85+
('Pacific/Samoa', 'Pacific/Samoa'),
86+
('US/Samoa', 'US/Samoa')
87+
)
88+
),
89+
...
90+
)
91+
92+
``GROUPED_COMMON_TIMEZONES_CHOICES``
93+
------------------------------------
94+
.. py:data:: GROUPED_COMMON_TIMEZONES_CHOICES
95+
96+
Returns choices grouped by the timezone offset and ordered alphabetically by
97+
their Olson Time Zone name populated from |pytz.common_timezones|_.
98+
99+
.. code-block:: python
100+
101+
>>> from timezone_utils.choices import GROUPED_ALL_TIMEZONES_CHOICES
102+
>>> print GROUPED_ALL_TIMEZONES_CHOICES
103+
(
104+
(
105+
'GMT-11:00',
106+
(
107+
('Pacific/Midway', 'Pacific/Midway'),
108+
('Pacific/Niue', 'Pacific/Niue'),
109+
('Pacific/Pago_Pago', 'Pacific/Pago_Pago')
110+
)
111+
),
112+
(
113+
'GMT-10:00',
114+
(
115+
('America/Adak', 'America/Adak'),
116+
('Pacific/Honolulu', 'Pacific/Honolulu'),
117+
('Pacific/Johnston', 'Pacific/Johnston'),
118+
('Pacific/Rarotonga', 'Pacific/Rarotonga'),
119+
('Pacific/Tahiti', 'Pacific/Tahiti'),
120+
('US/Hawaii', 'US/Hawaii')
121+
)
122+
),
123+
(
124+
'GMT-09:30',
125+
(
126+
('Pacific/Marquesas', 'Pacific/Marquesas'),
127+
)
128+
),
129+
...
130+
)
131+
60132
``PRETTY_ALL_TIMEZONES_CHOICES``
61133
--------------------------------
62134
.. py:data:: PRETTY_ALL_TIMEZONES_CHOICES
@@ -107,14 +179,16 @@ Contains constants and functions to generate model/form choices for time zones.
107179
...
108180
)
109181
110-
``get_choices(timezones)``
111-
--------------------------
112-
.. py:function:: get_choices(timezones)
182+
``get_choices(timezones, grouped=False)``
183+
-----------------------------------------
184+
.. py:function:: get_choices(timezones, grouped=False)
113185
114186
Retrieves timezone choices from any iterable (normally from `pytz <pytz.sourceforge.net/>`_).
115187
116188
:param timezones: Any iterable that contains valid Olson Time Zone strings.
117189
:type timezones: iterable
190+
:param grouped: Whether to group the choices by time zone offset.
191+
:type grouped: bool
118192
:return: A tuple containing tuples of time zone choices.
119193
:rtype: tuple
120194
:raises pytz.exceptions.UnknownTimeZoneError: if the string from the iterable ``timezones``

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
# built documents.
5252
#
5353
# The short X.Y version.
54-
version = '0.7'
54+
version = '0.8'
5555
# The full version, including alpha/beta/rc tags.
56-
release = '0.7'
56+
release = '0.8'
5757

5858
# The language for content autogenerated by Sphinx. Refer to documentation
5959
# for a list of supported languages.

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, 7)
1+
__version__ = (0, 8)
22
VERSION = '.'.join(map(str, __version__))

timezone_utils/fields.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ def _convert_value(self, value, model_instance, add):
320320
# Retrieve the time override
321321
time_override = self._get_time_override()
322322

323+
# Convert the value to the correct timezone prior to applying the
324+
# time_override
325+
if not value.tzinfo == tz:
326+
value = value.astimezone(tz)
327+
323328
# Convert the value to the date/time
324329
value = datetime.combine(
325330
date=value.date(),

0 commit comments

Comments
 (0)