Date, time, number etc. formats
Date, time, number etc. formats
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.
- Centaur
- Posts: 1083
- Joined: Tue 05 Apr, 2005 20:09
- Location: Novosibirsk, Russia
- Been thanked: 2 times
Re: Date, time, number etc. formats
You might want to read the MSDN Library for GetDateFormat, GetTimeFormat, GetNumberFormat, and probably the whole National Language Support category.
Re: Date, time, number etc. formats
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.
- Centaur
- Posts: 1083
- Joined: Tue 05 Apr, 2005 20:09
- Location: Novosibirsk, Russia
- Been thanked: 2 times
Re: Date, time, number etc. formats
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.)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.
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.
Again, examples please.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.
I have just tried this:
Code: Select all
GetNumberFormatW(LOCALE_USER_DEFAULT, 0, L"31415.926535", 0, buf, sizeof(buf) / sizeof(buf[0]));
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.
Re: Date, time, number etc. formats
Short date format as per Control Panel: 31.1.2009Centaur 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.
FAR would display: 31.01.2009 (notice the extra zero for month)
GetDateFormat: 31.1.2009 (matching short date format)
I could, but I would prefer to use FAR's format, to keep konsistent with other FAR's panels.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.
Control Panel: 123(space)456(space)789Again, examples please.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.
FAR: 123(some character above 128, don't know which exactly)456(that character again)789
GetDateFormat: 123(space)456(space)789
I am using the 1.75 branch of FAR, so no unicode for me.I have just tried this: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.Code: Select all
GetNumberFormatW(LOCALE_USER_DEFAULT, 0, L"31415.926535", 0, buf, sizeof(buf) / sizeof(buf[0]));
- Centaur
- Posts: 1083
- Joined: Tue 05 Apr, 2005 20:09
- Location: Novosibirsk, Russia
- Been thanked: 2 times
Re: Date, time, number etc. formats
That’s a bug in FAR.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 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: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
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 wrote:I am using the 1.75 branch of FAR, so no unicode for me.
Re: Date, time, number etc. formats
Possibly. I like it that way, though.Centaur wrote:That’s a bug in FAR.
Whatever. It is the default behavior and I would like to replicate it.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.
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.Shame on you.pepak wrote:I am using the 1.75 branch of FAR, so no unicode for me.
- Centaur
- Posts: 1083
- Joined: Tue 05 Apr, 2005 20:09
- Location: Novosibirsk, Russia
- Been thanked: 2 times
Re: Date, time, number etc. formats
If you like it, you should be consistent and configure it system-wide.pepak wrote:Possibly. I like it that way, though.Centaur wrote:That’s a bug in FAR.
Anyway, GetNumberFormat does that. You only need to convert the result to the OEM code page.pepak wrote:Whatever. It is the default behavior and I would like to replicate it.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.
You seem to be developing a plugin for an outdated version. Which is likely not to be unicode-friendly.pepak wrote: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.Shame on you.pepak wrote:I am using the 1.75 branch of FAR, so no unicode for me.
Re: Date, time, number etc. formats
Sorry, but that's nonsense. Different uses have different optimal display formats.Centaur wrote:If you like it, you should be consistent and configure it system-wide.
First, FAR 1.75 is being developed side by side with FAR 2.0.Centaur wrote:You seem to be developing a plugin for an outdated version. Which is likely not to be unicode-friendly.
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...).