This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Missing documentation on strftime modifier O
Type: enhancement Stage:
Components: Documentation Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: aseques, belopolsky, docs@python, eric.smith, eryksun, p-ganssle
Priority: normal Keywords:

Created on 2019-09-19 21:51 by aseques, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg352816 - (view) Author: Joan (aseques) Date: 2019-09-19 21:51
In the documentation at https://docs.python.org/3.9/library/datetime.html#strftime-strptime-behavior there's an omission of one of the modifiers that can be add to the strftime parameters (O and E)


Quoting from  http://man7.org/linux/man-pages/man3/strftime.3.html


    Some conversion specifications can be modified by preceding the
    conversion specifier character by the E or O modifier to indicate
    that an alternative format should be used.  If the alternative format
    or specification does not exist for the current locale, the behavior
    will be as if the unmodified conversion specification were used. (SU)
    The Single UNIX Specification mentions %Ec, %EC, %Ex, %EX, %Ey, %EY,
    %Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy,
    where the effect of the O modifier is to use alternative numeric
    symbols (say, roman numerals), and that of the E modifier is to use a
    locale-dependent alternative representation.


The modifier works as expected for the O modifier returning the values defined in ab_alt_mon and alt_mon from the locale (instead of the ones defined in abmon and mon.
I haven't been able to get any results with the E modifier (might not be yet defined in any locale)

A small snippet of code to see the difference:
    import locale
    from datetime import datetime
    locale.setlocale(locale.LC_ALL, 'ca_AD.utf8')
    locale.setlocale(locale.LC_ALL, 'ca_ES.utf8')
    now = datetime.now() # current date and time
    date_time = now.strftime("|%Ob|%b|||%OB|%B|")
    print("date and time:",date_time)
msg352820 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-09-20 00:29
Have you tried this on Windows or macOS?
msg352824 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-09-20 03:05
> Have you tried this on Windows or macOS?

3.5+ in Windows uses ucrt, which quietly ignores 'E' and 'O' strftime modifiers. From ucrt\time\wcsftime.cpp:

            // Skip ISO E and O alternative representation format modifiers.  We
            // do not support alternative formats in any locale.
            if (*format_it == L'E' || *format_it == L'O')
            {
                ++format_it;
            }

Example:

    >>> locale.setlocale(locale.LC_ALL, 'ca_ES.utf8')
    'ca_ES.utf8'
    >>> time.strftime('%b|%Ob')
    'set.|set.'

2.7 uses the old MSVC runtime, in which the 'E' and 'O' modifiers are invalid.

Example:

    >>> locale.setlocale(locale.LC_ALL, 'cat_esp')
    'Catalan_Spain.1252'
    >>> time.strftime('%b')
    'set.'
    >>> time.strftime('%Ob')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Invalid format string
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82409
2019-09-20 03:05:44eryksunsetnosy: + eryksun
messages: + msg352824
2019-09-20 00:29:27eric.smithsetnosy: + eric.smith
messages: + msg352820
2019-09-19 21:58:23xtreaksetnosy: + belopolsky, p-ganssle
2019-09-19 21:51:22asequescreate