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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With