Skip to content

Commit 28572a5

Browse files
committed
Fix some formatter’s tokens handling
1 parent 019c36d commit 28572a5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- Fixed handling of `pytz` timezones.
8+
- Fixed some formatter's tokens handling.
89

910

1011
## [2.0.2] - 2018-05-29

pendulum/formatting/formatter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class Formatter:
9696
# Day of Week
9797
'd': lambda dt: '{:d}'.format(dt.day_of_week),
9898

99+
# Day of ISO Week
100+
'E': lambda dt: '{:d}'.format(dt.isoweekday()),
101+
99102
# Hour
100103
'HH': lambda dt: '{:02d}'.format(dt.hour),
101104
'H': lambda dt: '{:d}'.format(dt.hour),
@@ -321,7 +324,9 @@ def _format_localizable_token(self, dt, token, locale):
321324
return locale.get('translations.months.abbreviated')[dt.month]
322325
elif token == 'MMMM':
323326
return locale.get('translations.months.wide')[dt.month]
324-
elif token in ('dd', 'ddd'):
327+
elif token == 'dd':
328+
return locale.get('translations.days.short')[dt.day_of_week]
329+
elif token == 'ddd':
325330
return locale.get('translations.days.abbreviated')[dt.day_of_week]
326331
elif token == 'dddd':
327332
return locale.get('translations.days.wide')[dt.day_of_week]

tests/formatting/test_formatter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@pytest.fixture(autouse=True)
1010
def setup():
1111
Locale._cache['dummy'] = {}
12-
12+
1313
yield
1414

1515
del Locale._cache['dummy']
@@ -100,17 +100,23 @@ def test_day_of_week():
100100
d = pendulum.datetime(2016, 8, 28)
101101
assert f.format(d, 'd') == '0'
102102

103-
assert f.format(d, 'dd') == 'Sun'
103+
assert f.format(d, 'dd') == 'Su'
104104
assert f.format(d, 'ddd') == 'Sun'
105105
assert f.format(d, 'dddd') == 'Sunday'
106106

107-
assert f.format(d, 'dd', locale='fr') == 'dim.'
107+
assert f.format(d, 'dd', locale='fr') == 'di'
108108
assert f.format(d, 'ddd', locale='fr') == 'dim.'
109109
assert f.format(d, 'dddd', locale='fr') == 'dimanche'
110110

111111
assert f.format(d, 'do') == '0th'
112112

113113

114+
def test_day_of_iso_week():
115+
f = Formatter()
116+
d = pendulum.datetime(2016, 8, 28)
117+
assert f.format(d, 'E') == '7'
118+
119+
114120
def test_am_pm():
115121
f = Formatter()
116122
d = pendulum.datetime(2016, 8, 28, 23)

0 commit comments

Comments
 (0)