HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.13k stars 673 forks source link

Why there is no support for using %O (and probably %E) modifiers on all flags? #465

Open hedayat opened 5 years ago

hedayat commented 5 years ago

In your library, just like any other widely used C/C++ API I know, use of %O modifier is limited to a number of flags. Since this library is going to be in C++20, I was wondering if this 'mistake' (IMHO) can be at least fixed here.

An important use-case that has always bothered me is "%OY". I wonder what was the rational here, but there is "%Oy" but not "%OY". So, 2 digit years are OK, but 4-digit years are English only?!

Is it possible to fix it at least for this library and std::chrono?

Regards

HowardHinnant commented 5 years ago

The practice follows the C library, which has %EY, %Ey, and %Oy, but not %OY. This library simply forwards these localized modifiers to the platform's locale support library. I wouldn't know what to do with %OY since the underlying locale support library also wouldn't know what to do with it.

hedayat commented 5 years ago

OK, so no hope for having the (IMHO) right thing in C++. :( Thanks.

hedayat commented 5 years ago

This issue can be closed. Actually I was hoping that this can be go into C++20 through this library and make others (including C library functions) think about adding support for it! :P

HowardHinnant commented 5 years ago

Just out of curiosity, what would be the difference between %OY and %EY?

hedayat commented 5 years ago

Well, I'm not sure about %EY exactly, as it does nothing in my locale. It seems that while %O modifier will use alternative numeric system, %E modifier is a completely alternative representation which might even not show the number of the year. Quoting https://en.cppreference.com/w/cpp/chrono/c/strftime about %EY:

writes year in the alternative representation, e.g.平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale

So, it is not just the numbers shown in the locale representation; it seems that it can show a totally different number!

But 2011 with %O modifier will remain 2011, but it'll be using locale specific numeric system. For example, in Persian & Arabic it'll be written as ۲۰۱۱. It is the same number, but with numbers in Arabic script rather than in Latin. Surprisingly, there is no %OC either. So, it is completely impossible to write 4 digit year in Persian for example. Even the date command show 2 digit year in Persian. %E modifer doesn't do anything under Persian locale.

I really don't know why this is like this, but seems a very strange limitation which exists everywhere (IIRC, KDE guys have implemented something for themselves as I recall it could show 4digit year in Persian. I'm not sure though.).

HowardHinnant commented 5 years ago

Thanks for the education!

hedayat commented 5 years ago

:) You're welcome!