Skip to content

Commit ff67135

Browse files
committed
Add strftime codes to string formatting doc and add Week of Year tokens
1 parent c99f242 commit ff67135

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

docs/docs/string_formatting.md

+47-43
Original file line numberDiff line numberDiff line change
@@ -104,49 +104,53 @@ and supports more directives.
104104
The following tokens are currently supported:
105105

106106

107-
| | Token | Output |
108-
| ------------------------------ | ------------- | ------------------------------------------ |
109-
| **Year** | YYYY | 2000, 2001, 2002 ... 2012, 2013 |
110-
| | YY | 00, 01, 02 ... 12, 13 |
111-
| | Y | 2000, 2001, 2002 ... 2012, 2013 |
112-
| **Quarter** | Q | 1 2 3 4 |
113-
| | Qo | 1st 2nd 3rd 4th |
114-
| **Month** | MMMM | January, February, March ... |
115-
| | MMM | Jan, Feb, Mar ... |
116-
| | MM | 01, 02, 03 ... 11, 12 |
117-
| | M | 1, 2, 3 ... 11, 12 |
118-
| | Mo | 1st 2nd ... 11th 12th |
119-
| **Day of Year** | DDDD | 001, 002, 003 ... 364, 365 |
120-
| | DDD | 1, 2, 3 ... 4, 5 |
121-
| **Day of Month** | DD | 01, 02, 03 ... 30, 31 |
122-
| | D | 1, 2, 3 ... 30, 31 |
123-
| | Do | 1st, 2nd, 3rd ... 30th, 31st |
124-
| **Day of Week** | dddd | Monday, Tuesday, Wednesday ... |
125-
| | ddd | Mon, Tue, Wed ... |
126-
| | dd | Mo, Tu, We ... |
127-
| | d | 0, 1, 2 ... 6 |
128-
| **Days of ISO Week** | E | 1, 2, 3 ... 7 |
129-
| **Hour** | HH | 00, 01, 02 ... 23, 24 |
130-
| | H | 0, 1, 2 ... 23, 24 |
131-
| | hh | 01, 02, 03 ... 11, 12 |
132-
| | h | 1, 2, 3 ... 11, 12 |
133-
| **Minute** | mm | 00, 01, 02 ... 58, 59 |
134-
| | m | 0, 1, 2 ... 58, 59 |
135-
| **Second** | ss | 00, 01, 02 ... 58, 59 |
136-
| | s | 0, 1, 2 ... 58, 59 |
137-
| **Fractional Second** | S | 0 1 ... 8 9 |
138-
| | SS | 00, 01, 02 ... 98, 99 |
139-
| | SSS | 000 001 ... 998 999 |
140-
| | SSSS ... | 000[0..] 001[0..] ... 998[0..] 999[0..] |
141-
| | SSSSSS | |
142-
| **AM / PM** | A | AM, PM |
143-
| **Timezone** | Z | -07:00, -06:00 ... +06:00, +07:00 |
144-
| | ZZ | -0700, -0600 ... +0600, +0700 |
145-
| | z | Asia/Baku, Europe/Warsaw, GMT ... |
146-
| | zz | EST CST ... MST PST |
147-
| **Seconds timestamp** | X | 1381685817, 1234567890.123 |
148-
| **Milliseconds timestamp** | x | 1234567890123 |
149-
107+
| | Token | Output | `strftime` Code |
108+
| ---------------------------- | ------------- | -------------------------------------------- | --------------------- |
109+
| **Year** | YYYY | 2000, 2001, 2002, ..., 2012, 2013 | %Y |
110+
| | YY | 00, 01, 02, ..., 12, 13 | %y |
111+
| | Y | 2000, 2001, 2002, ..., 2012, 2013 | %Y |
112+
| **Quarter** | Q | 1, 2, 3, 4 | |
113+
| | Qo | 1st, 2nd, 3rd, 4th | |
114+
| **Month** | MMMM | January, February, March, ... | %B |
115+
| | MMM | Jan, Feb, Mar, ... | %b |
116+
| | MM | 01, 02, 03, ..., 11, 12 | %m |
117+
| | M | 1, 2, 3, ..., 11, 12 | %-m* |
118+
| | Mo | 1st, 2nd, ..., 11th, 12th | |
119+
| **Day of Year** | DDDD | 001, 002, 003 ... 364, 365 | %j |
120+
| | DDD | 1, 2, 3, ..., 4, 5 | %-j* |
121+
| **Day of Month** | DD | 01, 02, 03, ..., 30, 31 | %d |
122+
| | D | 1, 2, 3, ..., 30, 31 | %-d* |
123+
| | Do | 1st, 2nd, 3rd, ..., 30th, 31st | |
124+
| **Day of Week** | dddd | Monday, Tuesday, Wednesday, ... | %A |
125+
| | ddd | Mon, Tue, Wed, ... | %a |
126+
| | dd | Mo, Tu, We, ... | |
127+
| | d | 0, 1, 2, ..., 6 | %w |
128+
| **Day of ISO Week** | E | 1, 2, 3, ..., 7 | %u |
129+
| **Week of Year** | WW | 00, 01, 02, ..., 52, 53 | %U |
130+
| | W | 0, 1, 2, ..., 52, 53 | %W |
131+
| **Hour** | HH | 00, 01, 02, ..., 23, 24 | %H |
132+
| | H | 0, 1, 2, ..., 23, 24 | %-H* |
133+
| | hh | 01, 02, 03, ..., 11, 12 | %I |
134+
| | h | 1, 2, 3, ..., 11, 12 | %-I* |
135+
| **Minute** | mm | 00, 01, 02, ..., 58, 59 | %M |
136+
| | m | 0, 1, 2, ..., 58, 59 | %-M* |
137+
| **Second** | ss | 00, 01, 02, ..., 58, 59 | %S |
138+
| | s | 0, 1, 2, ..., 58, 59 | %-S* |
139+
| **Fractional Second** | S | 0, 1, ..., 8, 9 | |
140+
| | SS | 00, 01, 02, ..., 98, 99 | |
141+
| | SSS | 000, 001, ..., 998, 999 | |
142+
| | SSSS | 0000, 0001, ..., 9998, 9999 | |
143+
| | SSSSS | 00000, 00001, ..., 99998, 99999 | |
144+
| | SSSSSS | 000000, 000001, ..., 999998, 999999 | %f |
145+
| **AM / PM** | A | AM, PM | %p |
146+
| **Timezone** | Z | -07:00, -06:00, ..., +06:00, +07:00 | |
147+
| | ZZ | -0700, -0600, ..., +0600, +0700 | %z |
148+
| | z | Asia/Baku, Europe/Warsaw, GMT ... | |
149+
| | zz | EST, CST, ..., MST, PST | %Z |
150+
| **Seconds timestamp** | X | 1381685817, 1234567890.123 | |
151+
| **Milliseconds timestamp** | x | 1234567890123 | |
152+
153+
\* _`strftime` directive depends on platform support. See [strftime.org](https://strftime.org#platforms) for details._
150154

151155
### Localized Formats
152156

pendulum/formatting/formatter.py

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class Formatter:
105105
"d": lambda dt: "{:d}".format(dt.day_of_week),
106106
# Day of ISO Week
107107
"E": lambda dt: "{:d}".format(dt.isoweekday()),
108+
# Week of Year
109+
"WW": lambda dt: "{:02d}".format(dt.week_of_year),
110+
"W": lambda dt: "{:d}".format(dt.week_of_year),
108111
# Hour
109112
"HH": lambda dt: "{:02d}".format(dt.hour),
110113
"H": lambda dt: "{:d}".format(dt.hour),

0 commit comments

Comments
 (0)