Skip to content

Commit 7c6b48e

Browse files
committed
Fix string formatting not supporting strftime format
1 parent 13ff4a0 commit 7c6b48e

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Fixed errors on some systems when retrieving timezone from clock files.
1010
- Fixed parsing of partial time.
1111
- Fixed parsing not raising an error for week 53 for ordinary years.
12+
- Fixed string formatting not supporting `strftime` format.
1213

1314

1415
## [2.0.1] - 2018-05-10

pendulum/mixins/default.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def for_json(self):
3131

3232
def __format__(self, format_spec):
3333
if len(format_spec) > 0:
34+
if '%' in format_spec:
35+
return self.strftime(format_spec)
36+
3437
return self.format(format_spec)
3538

3639
return str(self)

tests/date/test_strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def test_format():
4444
d = pendulum.Date(1975, 12, 25)
4545
assert '{}'.format(d) == '1975-12-25'
4646
assert '{:YYYY}'.format(d) == '1975'
47-
assert '{:%Y}'.format(d) == '%1975'
47+
assert '{:%Y}'.format(d) == '1975'

tests/datetime/test_strings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ def test_format():
135135
d = pendulum.datetime(1975, 12, 25, 14, 15, 16, tz='Europe/Paris')
136136
assert '{}'.format(d) == '1975-12-25T14:15:16+01:00'
137137
assert '{:YYYY}'.format(d) == '1975'
138-
assert '{:%Y}'.format(d) == '%1975'
138+
assert '{:%Y}'.format(d) == '1975'
139+
assert '{:%H:%M %d.%m.%Y}'.format(d) == '14:15 25.12.1975'
140+

0 commit comments

Comments
 (0)