[fpc-devel] Date and Time formatting via locale settings doesn't work under FPC 2.2.0

Michael Van Canneyt michael at freepascal.org
Mon Mar 10 14:33:37 CET 2008



On Mon, 10 Mar 2008, Graeme Geldenhuys wrote:

> Hi,
> 
> Reading the documentation about DateToStr() and DateTimeToStr(), it
> mentions that it takes the locale and regional settings in
> consideration when formatting the date and time.  I have a Linux PC
> that used the USA location at setup. A Linux PC that has South Africa
> as location (also specified in the installation setup). I also asked a
> fellow Russian developer to test on his PC.
> 
> We used the following line as mentioned in the docs.
> 
>   Writeln(Format ('Today is: %s',[DateToStr(Date)]));
> 
> Output under Windows (russian):
> Today is: 10.03.2008
> 
> Under Windows the formatting seems to work fine under all three PC's
> tested. Date formats changed accordingly.
> 
> 
> Output under Linux:
> Today is: 10-3-08
> 
> We got the exact same output on all three PC's tested. So basically
> the locale/region information is totally ignored!  Is the date format
> hard-coded under Linux or is there something vital that we are missing
> under Linux?

The locale/region information is ignored by default. I have a unit that loads this
information using Libc or the KDE settings, but it is not an option to
have this in sysutils by default, since it introduces a dependency on 
Libc.

The section on 'Localization support' in the sysutils documentation mentions
that:

Localization support depends on various constants and structures being
initialized correctly. On Windows and OS/2 this is done automatically: a
widestring manager is installed by default which helps taking care of the
current locale when performing various operations on strings. The various
internationalization settings (date/time format, currency, language etc) are
also initialized correctly on these platforms.


Michael.



More information about the fpc-devel mailing list