Recent

Author Topic: Should FormatDateTime default formatting use system locale settings?  (Read 2244 times)

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Greetings everyone,

By default, if I do
Code: Pascal  [Select][+][-]
  1. Label1.Caption := FormatDateTime('', Now());

I get: 20-08-20 11:53:32 in my label, which appears to be the German area(?) formatting.  My Linux system is using en_us locale, so the output should be something like 08-20-2020 11:53:32.  Shouldn't the default formatting use the system's locale?

This isn't a huge issue for me, because I just use the desired format string, but it seems weird that the default would not match my system locale.

Thanks!  :D
« Last Edit: August 20, 2020, 09:00:07 pm by willbprog9933 »
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #1 on: August 20, 2020, 09:18:31 pm »
Hi!

I noticed the same.

But this is not  german - this is a weird mix.

German would be: 20.08.2020

And why does FormatDateTime use per default the shortdate?
My locale wants the longdate.

Something went wrong in Laz 2.10

Winni


willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #2 on: August 20, 2020, 09:20:47 pm »
But this is not  german - this is a weird mix.

German would be: 20.08.2020

Sorry, wasn't sure about the exact location of that format. :-[

Even if I use 'f' as the format literal, it does shortdate and also uses that same non-en_us format.

Thanks!  :D
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #3 on: August 20, 2020, 09:29:12 pm »
Came across this issue a few days ago - try adding clocale to your uses clause.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #4 on: August 20, 2020, 09:33:06 pm »
Came across this issue a few days ago - try adding clocale to your uses clause.

Hello Sieben!

This works great, thank you! :-)

It would be nice to mention this in the Wiki or the FormatDateTime reference page.  Guess I could file a bug report...

Thanks again!  :D
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #5 on: August 20, 2020, 09:49:46 pm »
Hi Sieben!

Never would have come to this idea! Thanx!

Now it works as it should. Like in Laz 2.08

And documented in Nowhere Land?

Winni

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #6 on: August 20, 2020, 10:05:18 pm »
Picked it up somewhere, can't really remember now. But thank you as well - finally got me from lurking to registering. By the way - do we have to fill these captchas all the time now...?
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #7 on: August 20, 2020, 10:09:34 pm »
By the way - do we have to fill these captchas all the time now...?

Hi!

No - only at registration.

If you are registered name and pass do it.

Winni

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #8 on: August 20, 2020, 10:13:25 pm »
Guess I could file a bug report...


Hi!

Please file a  bugreport. The connection to clocale is so obscure that their should be a solution.
At least a clear documentation.

Winni

TRon

  • Hero Member
  • *****
  • Posts: 2514
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #9 on: August 20, 2020, 10:29:02 pm »
Picked it up somewhere, can't really remember now. But thank you as well - finally got me from lurking to registering. By the way - do we have to fill these captchas all the time now...?
They will disappear after a while. I do not know the exact criteria but wouldn't be surprised if it has anything to do with the number of posts you've made. Just keep it up and you'll (eventually) end up a happy customer  :)

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #10 on: August 20, 2020, 10:30:06 pm »
Please file a  bugreport. The connection to clocale is so obscure that their should be a solution.
At least a clear documentation.

Hi again,

I have filed the report here.

Thanks!  :D
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

TRon

  • Hero Member
  • *****
  • Posts: 2514
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #11 on: August 20, 2020, 10:33:10 pm »
@winni,

It is mentioned (see here https://www.freepascal.org/docs-html/rtl/clocale/index.html) but it is rather difficult to eventually end up there, e.g the locale related routines should point to it more obviously imho.

Thereby, it does not seem to mention MacOS/IOS specifics, see introduction here https://wiki.freepascal.org/FPC_New_Features_3.0.0#New_iosxlocale_unit

@willbprog9933
It is mentioned in the wiki under multiplatform programming. It is not a bug (as you filed it right now), rather a documentation related issue.
« Last Edit: August 20, 2020, 10:44:26 pm by TRon »

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #12 on: August 20, 2020, 10:34:29 pm »
@TRon - Thanks. I was afraid it would be sth like that, but ok. I'll try. ::)
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #13 on: August 20, 2020, 10:48:53 pm »
@Tron

Thanx.

* The Mac users use  iosxlocale
* The Unix/Linux users use clocale

And where do the Windows users get the information? The documentation is quiete unclear.

And Oracle just broke the compatibility to Linux kernel 5.18 for VirtualBox - so I have no Windows at hand.

Anyway: There should be a  clear documentation for this for the DateTime routines. And not only for the locale stuff.

Winni

TRon

  • Hero Member
  • *****
  • Posts: 2514
Re: Should FormatDateTime default formatting use system locale settings?
« Reply #14 on: August 20, 2020, 11:02:26 pm »
* The Mac users use  iosxlocale
or clocale... yes, confusing but it seems they are or can use both (just not at the same time, or last one included overwrites).

Quote
And where do the Windows users get the information? The documentation is quiete unclear.
I came across a wiki pages (I forgot to bookmark/take note of it) when Isearched for clocale related information, and that page mentioned that Wndows obtains these values from the OS by default. It seems only non windows platforms need to fall-back to other OS provided API's in order to be able to obtain these values accurately.

Quote
And Oracle just broke the compatibility to Linux kernel 5.18 for VirtualBox - so I have no Windows at hand.
... what else is new ... as they seem to be doing that with every new release :D

Quote
Anyway: There should be a  clear documentation for this for the DateTime routines. And not only for the locale stuff.
I agree.

It would imho be an idea to at least add it here (https://www.freepascal.org/docs-html/rtl/sysutils/datetimeroutines.html) and here (https://www.freepascal.org/docs-html/rtl/dateutils/index.html) as a bare minimum.

edit: on the other hand, I do not always seem to grasp which part(s) of the (online) documentation is platform specific and what not, and for/on which platform it was constructed  :-\

edit2: Ah, thanks to Michael. It was actually here (https://www.freepascal.org/docs-html/current/rtl/sysutils/localization.html) that I've read it
« Last Edit: August 20, 2020, 11:32:30 pm by TRon »

 

TinyPortal © 2005-2018