Skip to content

Commit d4a98db

Browse files
committed
Adds the timezones attribute to expose available timezones
1 parent d3631c2 commit d4a98db

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Added a `timezones` module attribute to expose available timezones.
8+
9+
310
## [1.2.5] - 2017-09-04
411

512
### Fixed
@@ -394,7 +401,7 @@ Initial release
394401

395402

396403

397-
[Unreleased]: https://github.com/sdispater/pendulum/compare/1.2.5...master
404+
[Unreleased]: https://github.com/sdispater/pendulum/compare/master...develop
398405
[1.2.5]: https://github.com/sdispater/pendulum/releases/tag/1.2.5
399406
[1.2.4]: https://github.com/sdispater/pendulum/releases/tag/1.2.4
400407
[1.2.3]: https://github.com/sdispater/pendulum/releases/tag/1.2.3

docs/_docs/instantiation.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ and the timezone will be created for you.
2424
Supported strings for timezones are the one provided by the `IANA time zone database <https://www.iana.org/time-zones>`_.
2525
The special ``local`` string is also supported and will return your current timezone.
2626

27+
As of release 1.3.0, available timezones are exposed via the ``timezones`` attribute.
28+
29+
.. code-block:: python
30+
31+
import pendulum
32+
33+
pendulum.timezones
34+
('CET',
35+
'CST6CDT',
36+
'Cuba',
37+
'EET',
38+
'Egypt',
39+
'Eire',
40+
...,
41+
'US/Michigan',
42+
'US/Mountain',
43+
'US/Pacific',
44+
'US/Pacific-New',
45+
'US/Samoa')
46+
2747
This is again shown in the next example which also introduces the ``now()`` function.
2848

2949
.. code-block:: python

pendulum/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@
7777
period = Period
7878

7979
# Timezones
80-
from .tz import timezone, local_timezone, UTC
80+
from .tz import timezone, timezones, local_timezone, UTC

pendulum/tz/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# -*- coding: utf-8 -*-
22

3+
import pytzdata
4+
35
from .timezone import Timezone, FixedTimezone, UTC
46
from .local_timezone import LocalTimezone
57

68

9+
timezones = pytzdata.timezones
10+
11+
712
def timezone(name):
813
"""
914
Loads a Timezone instance by name.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tzlocal
22
python-dateutil
3-
pytzdata
3+
pytzdata>=2017.2.2

tests/tz_tests/test_timezones.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import pendulum
4+
5+
6+
def test_timezones():
7+
zones = pendulum.timezones
8+
9+
assert 'America/Argentina/Buenos_Aires' in zones
10+
11+
12+
def test_timezones_are_loadable():
13+
zones = pendulum.timezones
14+
15+
for zone in zones:
16+
pendulum.timezone(zone)

0 commit comments

Comments
 (0)