Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the date format for the current locale

When I first stumbled across the constant defaultTimeLocale in System.Locale, I supposed it should contain the default TimeLocale for the current locale.

After some trying around, I realized that it always contains the same constants and looking at the source code of System.Locale quickly revealed that it's in fact only a constant. (Later I realized that the type also tells me that. Since defaultTimeLocale isn't an IO value and doesn't take any arguments it has to be constant.)

What is the way in Haskell to get the current TimeLocale with respect to the current locale?

like image 326
Kritzefitz Avatar asked Jan 21 '15 21:01

Kritzefitz


People also ask

How do I get a locale date?

Use the toLocaleString() method to get a date and time in the user's locale format, e.g. date. toLocaleString() . The toLocaleString method returns a string representing the given date according to language-specific conventions.

What is locale date?

The LOCALE functions take an alphanumeric item (a character string) in the format of a date, for the LOCALE-DATE intrinsic function, or in the format of a time, for the LOCALE-TIME intrinsic function and return another alphanumeric item with the date or time formatted in a culturally appropriate way.


1 Answers

System.CurrentLocale.currentLocale :: IO TimeLocale

from package current-locale looks suitable.

I did not test it. Looking at its source code, it should work. I actually do not like it very much since underneath it spawns four date subprocesses (!), which is rather overkill for this simple task, IMHO.

Probably it can be rewritten to use some C or POSIX function instead.

like image 129
chi Avatar answered Sep 19 '22 10:09

chi