[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lib/strftime.c bug for %r
From: |
Jim Meyering |
Subject: |
Re: lib/strftime.c bug for %r |
Date: |
Thu, 29 May 2003 13:58:52 +0200 |
[To the glibc folks, strftime.c's %r directive works fine for strftime
as compiled for libc, but not for other applications, i.e., those without
_NL_CURRENT. The patch below fixes that. FYI, the coreutils have to
compile lib/strftime.c unconditionally, because ls and date provide
support for the %N directive:
%N nanoseconds (000000000..999999999)
]
Regarding this thread:
http://mail.gnu.org/archive/html/bug-coreutils/2003-05/msg00058.html
Daniel Yacob <address@hidden> wrote:
> I'll send my data this evening. French is probably not the best
...
No need.
I've studied this code some more and see what you mean, now.
Here's a good example:
On my system, en_HK uses this format string for %r:
$ LC_ALL=en_HK locale -k t_fmt_ampm
t_fmt_ampm="%p%I:%M:%S %Z"
And perl's strftime gives a reasonable-looking result:
$ LC_ALL=en_HK \
perl -MPOSIX -e 'print strftime "%r\n",localtime '`date -d 2003-01-01 +%s`
AM12:00:00 CEST
but GNU date from coreutils-5.0 gets it wrong:
$ LC_ALL=en_HK date --date 2003-01-01 +%r
12:00:00 AM
With the patch below, date gives the same result as Perl,
modulo the time zone name:
$ LC_ALL=en_HK ./date --date 2003-01-01 +%r
AM12:00:00 CET
As for the time zone difference, I wonder if Perl-5.8.0 got it wrong,
since it seems to be using the current date to calculate CEST,
rather than the supplied one (which would give CET).
BTW, there's no problem in glibc itself, since when it's being compiled,
_NL_CURRENT is always defined.
2003-05-29 Jim Meyering <address@hidden>
* time/strftime.c (my_strftime) [!defined _NL_CURRENT && HAVE_STRFTIME]:
Use underlying_strftime for %r.
Suggested by Daniel Yacob <address@hidden>.
Index: time/strftime.c
===================================================================
RCS file: /cvs/glibc/libc/time/strftime.c,v
retrieving revision 1.94
diff -u -p -r1.94 strftime.c
--- time/strftime.c 11 May 2003 22:41:58 -0000 1.94
+++ time/strftime.c 29 May 2003 11:51:31 -0000
@@ -1144,13 +1144,17 @@ my_strftime (s, maxsize, format, tp ut_a
goto subformat;
case L_('r'):
-#ifdef _NL_CURRENT
+#if !defined _NL_CURRENT && HAVE_STRFTIME
+ goto underlying_strftime;
+#else
+# ifdef _NL_CURRENT
if (*(subfmt = (const CHAR_T *) _NL_CURRENT (LC_TIME,
NLW(T_FMT_AMPM)))
== L_('\0'))
-#endif
+# endif
subfmt = L_("%I:%M:%S %p");
goto subformat;
+#endif
case L_('S'):
if (modifier == L_('E'))
pgpbnR0awVWL1.pgp
Description: PGP signature