Date, time, number etc. formats

A place where plug-in developers can share their knowledge and experience.
Post Reply
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Date, time, number etc. formats

Post by pepak »

Does FAR publish some functions that could be used for formatting locale-specific items such as date, time or numbers? Specifically, in my plugin I would like to mimic the dialog that appears when you attempt to overwrite a file - and, being a beginner in C, can't find a way to format either file date or file size.
User avatar
Centaur
Posts: 1083
Joined: Tue 05 Apr, 2005 20:09
Location: Novosibirsk, Russia
Been thanked: 2 times

Re: Date, time, number etc. formats

Post by Centaur »

You might want to read the MSDN Library for GetDateFormat, GetTimeFormat, GetNumberFormat, and probably the whole National Language Support category.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Date, time, number etc. formats

Post by pepak »

I did. The problem with these functions is that they don't match FAR's standard behavior: For example, with date, FAR uses the proper ordering of items from short date format (and, presumably, date separators), BUT it forces lengths (2 digits for day and month, 4 digits for year). I couldn't find a way to immitate that with GetDateFormat - either I can match order and separator, but not lengths, or force all three. It is easier with time, where I can get the result I need.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Date, time, number etc. formats

Post by pepak »

Forgot: With GetNumberFormat, I can almost get the same result as FAR - except that FAR has a special character for decimal and thousands separator.
User avatar
Centaur
Posts: 1083
Joined: Tue 05 Apr, 2005 20:09
Location: Novosibirsk, Russia
Been thanked: 2 times

Re: Date, time, number etc. formats

Post by Centaur »

pepak wrote:I did. The problem with these functions is that they don't match FAR's standard behavior: For example, with date, FAR uses the proper ordering of items from short date format (and, presumably, date separators), BUT it forces lengths (2 digits for day and month, 4 digits for year). I couldn't find a way to immitate that with GetDateFormat - either I can match order and separator, but not lengths, or force all three. It is easier with time, where I can get the result I need.
Could you provide examples? What your date/time formats are set to in Control Panel, what FAR displays, and what you get from GetDateFormat. (If your short date format, as shown by Control Panel, has two digits for year, it is a configuration error on your machine. It’s almost a decade past Year 2000, everyone has had enough time to take the lesson.)

You can also choose to subtly push your users towards the international date/time format standard, ISO 8601, by passing "YYYY-MM-dd" to GetDateFormat.
pepak wrote:Forgot: With GetNumberFormat, I can almost get the same result as FAR - except that FAR has a special character for decimal and thousands separator.
Again, examples please.

I have just tried this:

Code: Select all

GetNumberFormatW(LOCALE_USER_DEFAULT, 0, L"31415.926535", 0, buf, sizeof(buf) / sizeof(buf[0]));
and it returned L"31'415,93", the same way I set in Control Panel just for this crazy test. FAR panels also displayed the configured thousand separator once I restarted it.

There is a registry tweak (TechInfo #78) to change the decimal and thousand separators in FAR, which is not a good idea. You can however read out that value and pass the appropriate strings in the NUMBERFMT structure to GetNumberFormat.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Date, time, number etc. formats

Post by pepak »

Centaur wrote:Could you provide examples? What your date/time formats are set to in Control Panel, what FAR displays, and what you get from GetDateFormat.
Short date format as per Control Panel: 31.1.2009
FAR would display: 31.01.2009 (notice the extra zero for month)
GetDateFormat: 31.1.2009 (matching short date format)
You can also choose to subtly push your users towards the international date/time format standard, ISO 8601, by passing "YYYY-MM-dd" to GetDateFormat.
I could, but I would prefer to use FAR's format, to keep konsistent with other FAR's panels.
pepak wrote:Forgot: With GetNumberFormat, I can almost get the same result as FAR - except that FAR has a special character for decimal and thousands separator.
Again, examples please.
Control Panel: 123(space)456(space)789
FAR: 123(some character above 128, don't know which exactly)456(that character again)789
GetDateFormat: 123(space)456(space)789
I have just tried this:

Code: Select all

GetNumberFormatW(LOCALE_USER_DEFAULT, 0, L"31415.926535", 0, buf, sizeof(buf) / sizeof(buf[0]));
and it returned L"31'415,93", the same way I set in Control Panel just for this crazy test. FAR panels also displayed the configured thousand separator once I restarted it.
I am using the 1.75 branch of FAR, so no unicode for me.
User avatar
Centaur
Posts: 1083
Joined: Tue 05 Apr, 2005 20:09
Location: Novosibirsk, Russia
Been thanked: 2 times

Re: Date, time, number etc. formats

Post by Centaur »

pepak wrote:Short date format as per Control Panel: 31.1.2009
FAR would display: 31.01.2009 (notice the extra zero for month)
GetDateFormat: 31.1.2009 (matching short date format)
That’s a bug in FAR.
pepak wrote:Control Panel: 123(space)456(space)789
FAR: 123(some character above 128, don't know which exactly)456(that character again)789
GetDateFormat: 123(space)456(space)789
That’s most probably not a space but a U+00A0 non-breaking space, which is 0xFF in most European OEM code pages and 0xA0 in most ANSI code pages. If you see that character in FAR, that’s a bug in your fonts. Every once in a while, some poor soul enables Large Fonts, chooses the 10×20 bitmap font for his console, and then comes screaming that “FAR displays sizes in hexadecimal” because in the 866 code page version of that particular font the non-breaking space looks visually identical to the letter 'a'.
pepak wrote:I am using the 1.75 branch of FAR, so no unicode for me.
Shame on you. But if all your separators are representable in both your ANSI and OEM code pages, you can use the ANSI version and convert to OEM afterwards; or if your separators are representable in OEM, you can use the Unicode version and then convert to OEM. (You are not still using Windows 9x, are you?)
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Date, time, number etc. formats

Post by pepak »

Centaur wrote:That’s a bug in FAR.
Possibly. I like it that way, though.
That’s most probably not a space but a U+00A0 non-breaking space, which is 0xFF in most European OEM code pages and 0xA0 in most ANSI code pages.
Whatever. It is the default behavior and I would like to replicate it.
pepak wrote:I am using the 1.75 branch of FAR, so no unicode for me.
Shame on you.
Why? As far as I was able to ascertain, the 2.0 branch only has two significant new features, none of which is important (or even useful) for me - unicode and open-source. They sure don't offset the problem that I am using several plugins which are not unicode-friendly and likely won't be anytime soon, if ever.
User avatar
Centaur
Posts: 1083
Joined: Tue 05 Apr, 2005 20:09
Location: Novosibirsk, Russia
Been thanked: 2 times

Re: Date, time, number etc. formats

Post by Centaur »

pepak wrote:
Centaur wrote:That’s a bug in FAR.
Possibly. I like it that way, though.
If you like it, you should be consistent and configure it system-wide.
pepak wrote:
That’s most probably not a space but a U+00A0 non-breaking space, which is 0xFF in most European OEM code pages and 0xA0 in most ANSI code pages.
Whatever. It is the default behavior and I would like to replicate it.
Anyway, GetNumberFormat does that. You only need to convert the result to the OEM code page.
pepak wrote:
pepak wrote:I am using the 1.75 branch of FAR, so no unicode for me.
Shame on you.
Why? As far as I was able to ascertain, the 2.0 branch only has two significant new features, none of which is important (or even useful) for me - unicode and open-source. They sure don't offset the problem that I am using several plugins which are not unicode-friendly and likely won't be anytime soon, if ever.
You seem to be developing a plugin for an outdated version. Which is likely not to be unicode-friendly.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Date, time, number etc. formats

Post by pepak »

Centaur wrote:If you like it, you should be consistent and configure it system-wide.
Sorry, but that's nonsense. Different uses have different optimal display formats.
Centaur wrote:You seem to be developing a plugin for an outdated version. Which is likely not to be unicode-friendly.
First, FAR 1.75 is being developed side by side with FAR 2.0.

Second, if an "up-to-date version" doesn't have the features I need and an "outdated version" does, I don't see a reason to switch to the new version.

Third, the plugin started years ago (not sure if FAR 2.0 was even available back then) as a simple update of an official plugin. It grew slowly over the time, when I gathered enough incentives to update and enough courage to even try (it was the first, and in fact still is the first program written in C that I worked on - my focus is on other languages). I may, some time, update it to work with FAR 2.0 (should be easy enough to do using a diff tool, first between FAR 1.7 and 2.0 versions of that original plugin, then between the original version and my version). I am not too hot for that, though - I have no idea what is different when one wants to use unicode, and if I could overcome that, I don't know how I would debug it (considering that I don't even run FAR 2.0...).
User avatar
t-rex
Страшный и ужасный
Posts: 4910
Joined: Tue 15 Mar, 2005 16:17
Location: Tel-Aviv
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: Date, time, number etc. formats

Post by t-rex »

pepak
Far 1.75 is not developed anymore, just bugfixes mainly.
Post Reply

Return to “Plug-In Developers”