#785118 coreutils: date : format %p %P do not work properly

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
Date:
2015-05-17 15:00:05 UTC
Severity:
normal
#785118#5
Date:
2015-05-12 13:36:17 UTC
From:
To:
Dear Maintainer,

I'm just upgrading my server from debian 7 (wheezy) to debian 8 (jessie) and several of my scripts are not working anymore. After some tests, it turns out that the problem likely comes from the fact the 'date' function does not work as expected.

In wheezy, the command line
would have returned

In jessie, the same command line returns
omitting PM.

As a consequence of this omission, my scripts are crashing.

Have you got any idea why this is happening?

Best regards,
Sebastien Legrand



*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
   * What was the outcome of this action?
   * What outcome did you expect instead?

*** End of the template - remove these template lines ***

#785118#10
Date:
2015-05-12 13:51:33 UTC
From:
To:
I can't reproduce it:
20150512.AM

If I had to guess, I'd say it's a locale issue. What does
env LANG=C LC_ALL=C /bin/date +"%Y%m%d.%p"
return?

If that works, what does
locale
return when run by itself?

Mike Stone

#785118#15
Date:
2015-05-12 15:49:59 UTC
From:
To:
"am_pm and t_fmt_ampm - should be empty if using 24 hour time"

Marko, that seems incorrect?
At least am_pm should be populated to
allow users to generate 12 hour time with strftime?

thanks,
Pádraig.

#785118#20
Date:
2015-05-12 16:55:40 UTC
From:
To:
Hi,

[CC'ing Keld with whom this issue was discussed some years ago]

I can't find references to the discussion I had with Keld earlier but
the rationale for not populating it was along the lines:

1) am_pm should be populated only if AM/PM convention is used to signal
applications they should not try to print them when using them is
unwanted. Seems that only the locale(5) commit messages, not the page
itself, spell this out:

http://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit/?id=b5d4168adfb426f45108ac2bf7c8b17b126b07a1
http://git.kernel.org/cgit/docs/man-pages/man-pages.git/commit/?id=0c2dbad182e40db2ca47128f229ca7dbd83e179f

2) what "unwanted" means is that in many cases 12 hour time with AM/PM
notation is alien thus generating such time representation under those
locales would be illogical (e.g. "5.34 ip." in Finnish context is
completely unnatural).

The same goes for various name_* keywords in LC_NAME, defining them for
locales where they are not used would not allow signaling applications
that under those locales their usage is unwanted.

Thanks,

#785118#25
Date:
2015-05-12 17:29:10 UTC
From:
To:
Thanks for the info.

Generally apps would not need to know whether to select
between 12 and 24?  Can't they just use the higher level
(and POSIX defined) %X to get the appropriate default?

I propose the wiki at least should be reworded to
state that am_pm should be omitted only when
it doesn't make any sense, like in Finland for example?

Also we'll need to fix up some locales that may have
blindly followed the existing advice.

The 12h format is not appropriate for Ireland at least:

$ LC_TIME=en_IE date +'def: %X | 12h: %r | 24h: %T'
def: 18:19:52 | 12h: 06:19:52  | 24h: 18:19:52

cheers,
Pádraig.

#785118#30
Date:
2015-05-12 18:49:58 UTC
From:
To:
Hi,

that might be a viable option but I think this should be discussed on
libc-alpha/libc-locales lists first to allow people there to comment and
see if we could even reach consensus. I don't know are there really
applications using an empty am_pm to check whether to use 12 or 24 hour
time (and if so, would that be a backward compatibility issue) but
sounds like by using %X things might be more flexible and portable.

No, that's backwards - many/most glibc locales were contributed around
'97/'98 or so by people who participated writing the related standards
and code, the wiki page has been around only for a couple of years, it
aims to document the existing situation and practices to make sure all
the locales are consistent and also to make it easier to contribute new
locales or validate existing ones.

If I'm not mistaken it has been this way since the locale was added in
1997. In general there's almost no activity at all on glibc locales
front so finding issues like this in not totally unexpected. Related to
this, it's unclear why the earlier mentioned script has started failing
after a distribution upgrade since there certainly haven't been any
efforts in upstream to actively remove am_pm or such from locales.

Thanks,

#785118#35
Date:
2015-05-12 15:40:58 UTC
From:
To:
%p is blank in many locales unfortunately.
You can see the am_pm vary with these commands:

$ LC_ALL=en_IE locale -k LC_TIME
$ LC_TIME=C locale -k LC_TIME
$ LC_ALL=zh_CN.utf8 date +%p
下午
$ LC_ALL=en_US.utf8 date +%p
PM
$ LC_ALL=en_US date +%p
PM

locales with blank am_pm should be fixed up to allow one to
get an explicit 12 hour format like `date +%I:%m%p` for example.

Note some locales (like en_GB for example) default
to 24 hour (t_fmt="%T"), and also provide an am_pm entry,
which is the correct behavior in my opinion.

cheers,
Pádraig

#785118#40
Date:
2015-05-17 14:26:30 UTC
From:
To:
I think that when running scripts you should ensure that the correct
locale is used, and in most cases that would be the "C" locale.
Better set it explicitely.

Best regards
keld