This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: LC_TIME: date_fmt vs d_t_fmt
- From: J William Piggott <elseifthen at gmx dot com>
- To: libc-alpha at sourceware dot org, keld at keldix dot com, cjlhomeaddress at gmail dot com, eggert at cs dot ucla dot edu, P at draigBrady dot com, jim at meyering dot net
- Date: Sun, 10 Apr 2016 21:23:43 -0400
- Subject: Re: LC_TIME: date_fmt vs d_t_fmt
- Authentication-results: sourceware.org; auth=none
- References: <20160410054026 dot GY6588 at vapier dot lan>
On 04/10/2016 01:40 AM, Mike Frysinger wrote:
> the `date` command will default to the LC_TIME.date_fmt field. it does
> this by looking up nl_langinfo(_DATE_FMT) (iff _DATE_FMT is defined).
> if that isn't available, it falls back to the default:
> %a %b %e %H:%M:%S %Z %Y
> this is required by POSIX for the POSIX locale, but works generally too.
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html#tag_20_30_10
>
> the GNU coreutils date code lives here (as does all this logic):
> http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/date.c
>
> the LC_TIME.date_fmt was first added to glibc here:
> https://sourceware.org/ml/libc-alpha/2000-10/msg00298.html
> https://sourceware.org/git/?p=glibc.git;a=commit;h=d8337213c83c3bd4aa32e16669745dd7ee32b329
>
> it quoted the XPG4 standard for the background. i haven't been able to
> locate that old standard, but all the ones i do have access to (SuSv2
> and newer) do not mention _date_fmt or date_fmt anywhere that i can find.
>
> we get a steady stream of complaints (some in our bugzilla, but via other
> sources as well like the mailing list or distro users) that the output of
> `date` does not match their expectations. in the end, they end up saying
> that want something that looks very much like `date +%c` which is what the
> LC_TIME.d_t_fmt field is set to.
>
> so what should we do here ? we provide 0 guidance to locale writers which
> means we get inconsistent behavior across locales. options:
> (1) punt date_fmt entirely (so `date` uses the POSIX default everywhere)
That will not satisfy the complaints requesting %c.
> (2) change date_fmt internally to always return %c
Some locales are taking advantage of date_fmt. Turkey and Uzbekistan,
for example, have date(1) default to displaying only the date, which
seems intuitive.
> (3) try to clearly define the difference between date_fmt and d_t_fmt --
> anyone know what that is ? or have access to the XPG4 definition ?
date_fmt: Locale's date and time representation for date(1).
d_t_fmt: Locale's date and time representation for strftime %c
> (4) somethine else ?
It looks like the commit that introduced date_fmt set its value for all
locales to the POSIX default format, and very few have been updated.
I would say for locales that have not changed the default value, you
could set it to d_t_fmt (providing it has been set to a locale specific
value).
Then for locale writer guidance, suggest setting date_fmt and d_t_fmt the
same, unless there is a locale specific reason for them to differ.
The only online documentation I have found for date_fmt and XPG is Solaris.
If I understand it correctly their tools default to XPG3 in /usr/bin and
XPG4 are in /usr/xpg4/bin:
http://docs.oracle.com/cd/E53394_01/html/E54776/xpg-5.html
For XPG3 d_t_fmt corresponded to the %c field descriptor and date_fmt
corresponded to the %C field descriptor:
http://docs.oracle.com/cd/E53394_01/html/E54776/locale-5.html
%c Locale's appropriate date and time
%C Locale's date and time representation as produced by date(1).
http://docs.oracle.com/cd/E53394_01/html/E54766/strftime-3c.html