msg115933 - (view) |
Author: Sverre Johansen (sverrejoh) |
Date: 2010-09-09 09:59 |
There seems to be a platform difference in the way stftime handles unknown format codes. In OSX Python removes the percentage sign from the returned string when the format code is unknown. In Linux it leaves it. Look at the following example: This is Python 3.1.2 in Ubuntu: Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> datetime.datetime.now().strftime("%q") '%q' And this is Python 3.1.2 on Max OSX: Python 3.1.2 (r312:79147, Sep 9 2010, 11:11:24) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> datetime.datetime.now().strftime("%q") 'q' I've gotten the same result in 2.5, 2.6 and 3.1. FYI, this broke some code that parsed the same string first with strftime, and then used string interpolation (The mac version deleted all percentage signs before '('): >>> datetime.datetime.now().strftime("%Y - %(foobar)s") % {"foobar": "egg"} This does not work in OSX. |
|
|
msg115937 - (view) |
Author: Sverre Johansen (sverrejoh) |
Date: 2010-09-09 10:35 |
This is because of differences in GNU and BSD C stdlib; I get the same results using the BSD and GNU versions of `date`. $ date +"%q" What does Python typically do in cases like this? |
|
|
msg115948 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-09-09 14:23 |
Python's strftime is a thin wrapper around the system strftime. This means, for example, that a slightly different set of % codes is supported on windows vs linux. So, from Python's point of view this is at *most* a doc bug. That said, I think there have been some rumblings about writing our own strftime, but I don't know if anyone is serious about it. |
|
|
msg115952 - (view) |
Author: Alexander Belopolsky (belopolsky) *  |
Date: 2010-09-09 15:47 |
> I think there have been some rumblings about writing our own strftime Yes, see issue #3173. Another related issue is #9650 which discusses how to properly document strftime codes. |
|
|
msg116132 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-09-11 23:26 |
I think supporting different specifiers is one thing, dropping the % character is another. This is how I understand the bug report. |
|
|
msg116141 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-09-12 00:54 |
But if it is a bug, it is a bug in OS/X, not in Python. Python could potentially fix it for python programs by providing our own strftime, but until someone does that the best we can do is a doc mention of this platform quirk. |
|
|
msg116143 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2010-09-12 01:04 |
Ah, I understand your first reply now. Thanks. Agreed on all your points. |
|
|
msg136152 - (view) |
Author: Ronald Oussoren (ronaldoussoren) *  |
Date: 2011-05-17 12:32 |
I've filed #9451707 about this in Apple's bug tracker. BTW. I don't think this is a platform bug, neither the manpage nor the unix specification at <http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html> specify what happens when you use an undocumented format specifier. |
|
|
msg136161 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2011-05-17 14:06 |
Right, that's why I said "if it is a bug" :) FreeBSD has the same behavior, so I'd actually prefer that Apple not "fix" this. It would be nice if FreeBSD did and Apple adopted it, though, since only dropping the % is the least intuitive approach to handling unknown codes I can think of. Is Apple tracking FreeBSD development at all these days, or are they a true fork now? |
|
|
msg136163 - (view) |
Author: Ronald Oussoren (ronaldoussoren) *  |
Date: 2011-05-17 14:52 |
I'm not sure if Apple's tracking FreeBSD, but they at the very least heavily borrow code (see <http://opensource.apple.com/source/Libc/Libc-594.9.4/> for libc) |
|
|
msg136183 - (view) |
Author: Santoso Wijaya (santoso.wijaya) * |
Date: 2011-05-17 21:23 |
`strftime` does not, indeed, seem to define what behaviour it is supposed to do when given non-supported format characters. Under Windows, in fact, it will crash the runtime (see: issue #10762). |
|
|
msg136208 - (view) |
Author: Marc-Andre Lemburg (lemburg) *  |
Date: 2011-05-18 07:53 |
Santoso Wijaya wrote: > > Santoso Wijaya <santoso.wijaya@gmail.com> added the comment: > > `strftime` does not, indeed, seem to define what behaviour it is supposed to do when given non-supported format characters. Under Windows, in fact, it will crash the runtime (see: issue #10762). According to POSIX, it is defined to be undefined: """ If a conversion specification does not correspond to any of the above, the behavior is undefined. """ Of course, crashing the runtime is not a good way to interpret this ;-) |
|
|
msg136211 - (view) |
Author: Santoso Wijaya (santoso.wijaya) * |
Date: 2011-05-18 08:22 |
Yeah, I meant undefined. I looked that up when writing a patch for issue #10762. Correction: It *used to* crash on Windows, before the patch was applied. |
|
|
msg401519 - (view) |
Author: Irit Katriel (iritkatriel) *  |
Date: 2021-09-09 21:10 |
This issue was created 11 years ago today. Let's celebrate its anniversary by resolving it! |
|
|
msg401593 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-09-10 16:27 |
New changeset e86bcfa58080f152f242c756f625f4015671f168 by Irit Katriel in branch 'main': bpo-9811: [doc] strftime handling of unsupported format specifiers is platform dependent (GH-28264) https://github.com/python/cpython/commit/e86bcfa58080f152f242c756f625f4015671f168 |
|
|
msg401610 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-09-10 19:53 |
New changeset 897e5aae748180acf8d546d14aeacaf02600fff9 by Miss Islington (bot) in branch '3.10': bpo-9811: [doc] strftime handling of unsupported format specifiers is platform dependent (GH-28264) (GH-28277) https://github.com/python/cpython/commit/897e5aae748180acf8d546d14aeacaf02600fff9 |
|
|
msg401611 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-09-10 19:53 |
New changeset baeaaecb8a97033bc2d07d51442cc8b1f89d410d by Miss Islington (bot) in branch '3.9': bpo-9811: [doc] strftime handling of unsupported format specifiers is platform dependent (GH-28264) (GH-28278) https://github.com/python/cpython/commit/baeaaecb8a97033bc2d07d51442cc8b1f89d410d |
|
|
msg401613 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2021-09-10 20:27 |
Is there anything else you wanted to do here, Irit? |
|
|
msg401615 - (view) |
Author: Irit Katriel (iritkatriel) *  |
Date: 2021-09-10 21:11 |
No, I think we're good. Thanks. |
|
|
msg403153 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2021-10-04 19:18 |
New changeset b1873d1e24ed5ef39f37ca3090c2f0c2b34ce23f by Pablo Galindo (Miss Islington (bot)) in branch '3.10': bpo-9811: [doc] strftime handling of unsupported format specifiers is platform dependent (GH-28264) (GH-28277) https://github.com/python/cpython/commit/b1873d1e24ed5ef39f37ca3090c2f0c2b34ce23f |
|
|