Reply To: TRzDateTimeEdit Localization Issue

#1124
Ray Konopka
Keymaster

    I was able to reproduce the problem that you are experiencing. I changed the format settings for Windows to be French (Canada). I only changed the general Format setting. I did not change any of the actually date/time formats.

    I then created a test project that has a TRzEdit and a TRzDateTimeEdit control on the main form. I put the TRzEdit so that I could tab into and out of the TRzDateTimeEdit. I also set the Format property of the TRzDateTimeEdit to ‘ddd dd-mmm-yyyy‘. I ran the app, click on the date-time edit and picked today’s date. I then clicked on the other edit control and that is when I got the exception.

    After some investigation, I was able to see why the error was occurring. Let me try to explain. As you discovered, the TRzDateTimeEdit uses the StrToDateEx function to parse the information in the edit to determine the date. Because a user is able to enter a date in the control and not select one from the dropdown calendar, the data that gets parsed could be in a variety of formats. In order to interpret the data entered and match it to date elements, the system ShortDateFormat is used as a guide. Well, actually an abbreviated version of the ShortDateFormat is used. For example, the default ShortDateFormat for French(Canada) is yyyy-MM-dd. This gets condensed to YMD. For English(United States), the ShortDateFormat is M/d/yyyy, which gets condensed to MDY. And for English(United Kingdom) the format is dd/MM/yyyy, which gets condensed to DMY.

    This approach is how the control is able to handle someone from the US entering 0405 into the control, tabbing away and the date is determined to be April 5. However, someone from the UK entering 0405 into the control will have the date determined to be May 4.

    So, what does all of this have to do with what you are experiencing. Well, the condensed ShortDateFormat for French (Canada) as noted above is YMD. However, the Format property of the control is set to ‘ddd dd-mmm-yyyy‘, which gets condensed to DMY. And this is the problem. The parsing code is trying to match the values in the text area to YMD, but the year and day values are swapped. The parsing code ends up matching 2019 to the day value, which is clearly invalid.

    The easiest solution is to change the Format property of the TRzDateTimeEdit control to ‘ddd yyyy-mmm-dd‘ so that it matches the YMD ShortDateFormat defined in the system.

    Ray