Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external strftime for Python? #47423

Open
smontanaro opened this issue Jun 23, 2008 · 17 comments
Open

external strftime for Python? #47423

smontanaro opened this issue Jun 23, 2008 · 17 comments
Labels
extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@smontanaro
Copy link
Contributor

BPO 3173
Nosy @gvanrossum, @loewis, @amauryfa, @abalkin, @vstinner, @ericvsmith, @merwok, @florentx, @berkerpeksag
Files
  • strftime.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2008-06-23.02:44:52.698>
    labels = ['type-feature']
    title = 'external strftime for Python?'
    updated_at = <Date 2014-06-29.22:36:42.704>
    user = 'https://github.com/smontanaro'

    bugs.python.org fields:

    activity = <Date 2014-06-29.22:36:42.704>
    actor = 'belopolsky'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2008-06-23.02:44:52.698>
    creator = 'skip.montanaro'
    dependencies = []
    files = ['10704']
    hgrepos = []
    issue_num = 3173
    keywords = ['patch']
    message_count = 17.0
    messages = ['68603', '68604', '68606', '69092', '75730', '107168', '107315', '111886', '111954', '125579', '125584', '125585', '125587', '125588', '125589', '146853', '163132']
    nosy_count = 11.0
    nosy_names = ['gvanrossum', 'loewis', 'amaury.forgeotdarc', 'belopolsky', 'vstinner', 'eric.smith', 'schmir', 'eric.araujo', 'cvrebert', 'flox', 'berker.peksag']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3173'
    versions = ['Python 3.3']

    @smontanaro
    Copy link
    Contributor Author

    Back in April we had a thread on xmlrpclib's problematic handling of dates
    before 1900:

    http://thread.gmane.org/gmane.comp.python.devel/93273/focus=93309
    

    I'm still of the opinion that strftime() is the culprit and xmlrpclib is
    just an innocent bystander. Guido worried that to correct this we'd have
    to
    implement strftime() from scratch.

    I took a different approach and scouted around for an existing version of
    strftime() which we could suck into the distribution. I found a modified
    version of the BSD 4.4 strftime which came with (I see to recall) Tcl.
    The attached patch is against the py3k svn repo. It passes all tests as
    far as I can tell.

    Also, see http://bugs.python.org/issue1777412 which appears to be related.

    @smontanaro
    Copy link
    Contributor Author

    Ummm... I think I only modified timemodule.c. datetimemodule.c
    probably needs a tweak as well. I need to get this off my desk though.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jun 23, 2008

    So how does it work for non-English locales?

    @smontanaro
    Copy link
    Contributor Author

    Good question. I don't claim that the strftime.c I found is complete
    for our needs, only that we can avoid the "rewrite strftime from
    scratch" problem Guido indicated.

    S

    @vstinner
    Copy link
    Member

    The issue bpo-1777412 has a working patch (for Python 2.6) which allows
    year < 1900 in time.strftime() and datetime.datetime.strftime().

    @abalkin
    Copy link
    Member

    abalkin commented Jun 6, 2010

    What platforms have broken strftime and how badly is it broken there?

    Is there a python version somewhere? PyPy?

    @abalkin abalkin self-assigned this Jun 6, 2010
    @abalkin abalkin added the type-feature A feature request or enhancement label Jun 6, 2010
    @amauryfa
    Copy link
    Member

    amauryfa commented Jun 8, 2010

    PyPy also calls the platform's strftime().

    @gvanrossum
    Copy link
    Member

    What about the licensing? That look like the BSD license *with* advertising clause...

    @abalkin
    Copy link
    Member

    abalkin commented Jul 29, 2010

    On Wed, Jul 28, 2010 at 11:22 PM, Guido van Rossum
    <report@bugs.python.org> wrote:
    ..

    What about the licensing? That look like the BSD license *with*
    advertising clause...

    I am not a lawyer and I am not intimately familiar with PSF policies,
    but this license does not look too dissimilar to the profile module
    license:

    # Permission to use, copy, modify, and distribute this Python software
    # and its associated documentation for any purpose (subject to the
    # restriction in the following sentence) without fee is hereby
    granted,
    # provided that the above copyright notice appears in all copies, and
    # that both that copyright notice and this permission notice appear in
    # supporting documentation, ...

    Actually, I wonder if pydoc profile is technically in violation of the
    InfoSeek license. More likely, however, is that the license text in
    the source file is not authoritative and PSF has a more permissive
    license to this code.

    Skip, can you clarify where the strftime code in your patch came from?
    In your first post you said that it came from Tcl, so it may have
    ActiveState copyright on at least portions of it.

    On the other hand, unless strftime code is already published under an
    acceptable license, I think rewriting this code from scratch would be
    easier than tracking down the owners and asking them to contribute it
    to python.

    @abalkin
    Copy link
    Member

    abalkin commented Jan 6, 2011

    Maybe rather than spending the effort maintaining a legacy API such as strftime, someone could look into implementing localized date formatting as defined by recent Unicode standards:

    http://unicode.org/reports/tr35/#Date_Format_Patterns

    Apparently there is a free implementation for Python out there:

    http://babel.edgewall.org/wiki/Documentation/dates.html#pattern-syntax

    See also msg107236 on issue bpo-8913.

    @ericvsmith
    Copy link
    Member

    I think we're stuck with strftime for quite a while, no matter how ugly it is. datetime.__format__ uses it, for example. Although maybe it's possible to write an strftime-format to new-format translator.

    If we're going to take this on (re-writing strftime), I think the way to do it is to have it take the locale info as a parameter, and if that parameter is NULL then look up the info in the current locale. It looks like it's still a problem to find all of the info in the locale on all platforms, though. Finding the locale info is no doubt the tricky part, as someone said.

    I agree it would be easier to write this from scratch rather than track down the licensing on the existing patch. As it is, there's just not much code there.

    @abalkin
    Copy link
    Member

    abalkin commented Jan 6, 2011

    On Thu, Jan 6, 2011 at 2:56 PM, Eric Smith <report@bugs.python.org> wrote:
    ..

    If we're going to take this on (re-writing strftime), I think the way to do it is to have it take the locale info as a
    parameter, and if that parameter is NULL then look up the info in the current locale.

    You may want to take a look at BSD-ish strftime_l function which is
    defined by POSIX.1-2008:

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

    @gvanrossum
    Copy link
    Member

    On Thu, Jan 6, 2011 at 11:56 AM, Eric Smith <report@bugs.python.org> wrote:

    If we're going to take this on (re-writing strftime), I think the way to do it is to have it take the locale info as a parameter, and if that parameter is NULL then look up the info in the current locale. It looks like it's still a problem to find all of the info in the locale on all platforms, though. Finding the locale info is no doubt the tricky part, as someone said.

    Hm, shouldn't the libc locale support offer the same set of locales
    and locale info that the libc strftime uses, on any platform? Or are
    there platforms whose libc strftime has better locale support than the
    libc getlocale implementation???

    @vstinner
    Copy link
    Member

    vstinner commented Jan 6, 2011

    The Qt library has its own strftime() implementation. The QLocale object has methods providing localized day and month names. For example, day names are implemented using a big ushort array (~20.000 bytes) which contains something like 'Sun;Mon;Tue;Wed;Thu;Fri;Sat;Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;S;M;T;W;T;F;S;7;1;2;3;4;5;6;;;;;;;;Dil;Wix;Qib;Rob;Kam;Jim;San;Dilbata;Wiixata;Qibxata;Roobii;Kamiisa;Jimaata;Sanbata;A;E;T;A;K;G;S;Aca;Etl;Tal;Arb;Kam;Gum;Sab;Acaada;Etleeni;Talaata;Arbaqa;Kamiisi;Gumqata;Sabti;1;2;3;4;5;6;7;So;Ma;Di;Wo;Do;Vr;Sa;Sondag;Maandag;Dinsdag;Woensdag;Donderdag;Vrydag;Saterdag;D;H;M;M;E;P;S;Die;H\xebn;Mar;M\xebr;(...)'.

    @vstinner
    Copy link
    Member

    vstinner commented Jan 6, 2011

    Is nl_langinfo() function reliable? On any OS? Can we use it to get day name, abbreviated day name, month name and abbreviated month name?

    We should maybe start with an implementation in Python? It's easier to write code in Python than in C, and because it can be reused on other Python implementations.

    @merwok
    Copy link
    Member

    merwok commented Nov 2, 2011

    Maybe rather than spending the effort maintaining a legacy API such as strftime, someone could
    look into implementing localized date formatting as defined by recent Unicode standards:
    http://unicode.org/reports/tr35/#Date_Format_Patterns

    This scheme is very elegant. I’d love to have built-in/stdlib support for it. Would it need to be implemented in C?

    Apparently there is a free implementation for Python out there:
    http://babel.edgewall.org/wiki/Documentation/dates.html#pattern-syntax

    Babel just rocks :)

    @abalkin
    Copy link
    Member

    abalkin commented Jun 19, 2012

    IANA is now distributing Olson's timezone database software which includes an implementation of strftime():

    http://www.iana.org/time-zones/repository/releases/tzcode2012b.tar.gz

    The code was designated as public domain by Arthur David Olson, but it seems to be based on code copyrighted by UCB and distributed under the BSD license. The code does seem to include some locale support.

    @abalkin abalkin removed their assignment Jun 29, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the extension-modules C modules in the Modules dir label Nov 28, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-feature A feature request or enhancement
    Projects
    Development

    No branches or pull requests

    8 participants