sanitize_strftime_format
Ensure that certain specifiers are correctly padded with leading zeros.
For years < 1000 specifiers %C, %F, %G, and %Y don't work as expected for strftime provided by glibc on Linux as they don't pad the year or century with leading zeros. Support for specifying the padding explicitly is available, however, which can be used to fix this issue.
FreeBSD, macOS, and Windows do not support explicitly specifying the padding, but return four digit years (with leading zeros) as expected.
This function checks whether the %Y produces a correctly padded string and, if not, makes the following substitutions:
- %C → %02C
- %F → %010F
- %G → %04G
- %Y → %04Y
See https://bugs.python.org/issue13305 for more details.
def sanitize_strftime_format(
fmt: string
) - > string
Ensure that certain specifiers are correctly padded with leading zeros.
Parameters
| Name | Type | Description |
|---|---|---|
| fmt | string | The strftime format string containing date/time specifiers to be validated and potentially modified for padding compatibility. |
Returns
| Type | Description |
|---|---|
string | The sanitized format string with explicit padding specifiers added if the platform's strftime implementation does not handle years before 1000 correctly. |