Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/DateUtils    [ Add a report in this area ]  
Report #:  104942   Status: Closed
FormatSettings ShortDateFormat and LongDateFormat contains wrong values
Project:  Delphi Build #:  XE2, ... XE6
Version:    20.0 Submitted By:   Heiko Duckstein
Report Type:  Basic functionality failure Date Reported:  4/16/2012 10:10:50 AM
Severity:    Serious / Highly visible problem Last Updated: 8/4/2014 4:44:26 PM
Platform:    All versions Internal Tracking #:   28331
Resolution: Test Case Error (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: 33
Description
As suggested in issue QC#88894, I'm filing a new QC report about the Topic.

QC#88894 was closed as 'Test Case Error'.
But, problem still occurs with Delphi XE2 Update 4(16.0.4429.46931).

For example, in German locale,
ShortDateFormat is 'dd/MM/yyyy'.
Correct value should be 'dd.MM.yyyy'.

Same problem with LongDateFormat.

DateToStr works correct but how can I show the current FormatString to the user?
Steps to Reproduce:
On German Computers:
- Look into FormatSettings.ShortDateFormat

Others:
TFormatSettings.Create('de-DE').ShortDateFormat

Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 4/17/2012 8:23:35 AM -
In my OS(Windows 7 64bit Japanese Edition/system locale is Japanese),
1. ShowMessage( FormatSettings.ShortDateFormat ); shows 'yyyy/MM/dd'
2. ShowMessage( TFormatSettings.Create('de-DE').ShortDateFormat ); shows 'dd/MM/yyyy'
3. ShowMessage( TFormatSettings.Create('ja-JP').ShortDateFormat ); shows 'yyyy/MM/dd'

What results do you get in your OS?

Tomohiro Takahashi at 4/17/2012 8:45:02 AM -
Your issue is caused by inner method 'FixDateSeparator' in TranslateDateFormat method as below.
As a resutl, '.' has been repalced with '/'.

[System.SysUtil.pas]
-----------
...
    ShortDateFormat := TranslateDateFormat(Locale, LOCALE_SSHORTDATE, 'm/d/yy', DateSeparator);
...
...
class function TFormatSettings.TranslateDateFormat(Locale: TLocaleID;
  LocaleType: Integer; const Default: string; const Separator: Char): string;
{$IFDEF MSWINDOWS}
...
...
  procedure FixDateSeparator(var DateFormat: string);
  var
    P: PChar;
  begin
    P := PChar(DateFormat);
    if P = nil then
      Exit;

    while P^ <> #0 do
    begin
      if P^ = Separator then
        P^ := '/';
      Inc(P);
    end;
  end;

begin
  ...
  Result := '';
  LFormat := GetLocaleStr(Locale, LocaleType, Default);
  ...
    { Adjust the date separator accordingly }
    FixDateSeparator(Result);
    Exit;
  end;
...
-----------

Tomohiro Takahashi at 4/17/2012 8:58:12 AM -
> ... how can I show the current FormatString to the user?
As a possible workaround, please try my code as below.
------------
uses StrUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  de_DE: TFormatSettings;
begin
  de_DE := TFormatSettings.Create('de-DE');
  de_DE.ShortDateFormat := ReplaceStr(de_DE.ShortDateFormat, '/', de_DE.DateSeparator);
  ShowMessage( de_DE.ShortDateFormat ); // dd.MM.yyyy
end;
------------

Heiko Duckstein at 4/20/2012 12:51:44 AM -
Yes, this works for German language. But how can I be sure that it is still correct in all of these hundreds of other locales?

What does this 'FixDateSeperator'-function fix? Is it possible to remove it in the next update.
I don't want to start using a custom-sysutils.pas...

Dalija Prasnikar at 4/18/2012 8:43:48 AM -
This whole formatting system is completely broken because Delphi translates default Windows formatting values into its own system. It creates problem for applications that allow independent format settings (besides Windows default ones) and for some languages it even formats wrong values.

Create form with one button and memo and add following code

procedure TForm1.Button1Click(Sender: TObject);
var
  fs: TFormatSettings;
  d: TDateTime;
begin
  d := now;
  fs := TFormatSettings.Create;
  Memo1.Lines.Add(FormatDateTime('ddddd', d, fs));
  Memo1.Lines.Add(FormatDateTime('dddddd', d, fs));
end;

Then open Control Panel Regional settings and try changing settings to Russian for example, after you apply settings, click button on the form and compare results in memo with Windows date preview in control panel. You will see that Delphi formats LongDateFormat wrong by replacing dot at the end with /. Same happens in number of other languages like Estonian, Latvian, Lithuanian, Kazakh...

Date formats are too complex to be messed around. Any translation and conversion can introduce errors.

Ivan Kozhuharov at 5/8/2012 12:26:47 PM -
The same - here - language is Bulgarian.
The correct date format is "dd.mm.yyyy ?.".
Delphi XE/XE2 function DateTimeToStr replace dot at the end with /.


Tomohiro Takahashi at 5/18/2012 9:33:05 PM -
This report was opened with valid Internal Tracking Number.
Thanks.

Ilian Yovchev at 8/8/2012 5:24:38 AM -
Please, apply following patched function in next updates.

//-------------------------------------------------------

  procedure FixDateSeparator(var DateFormat: string);
  var
    P: PChar;
    IsQuoted: boolean;
  begin
    P := PChar(DateFormat);
    if P = nil then
      Exit;

    IsQuoted := false;
    while P^ <> #0 do
    begin
      if (P^ = '''') then
        IsQuoted := not IsQuoted
      else if IsQuoted then
        // NEVER change quoted characters
      else if P^ = Separator then
        P^ := '/';

      Inc(P);
    end;
  end;

//-------------------------------------------------------

Christian Herrmann at 4/22/2014 2:46:36 AM -
2 years open and still not fixed in XE6 though there is a fix attached to this report? Thanks Embarcadero!
So we will still not upgrade... all hopes to XE7

Tomohiro Takahashi at 8/4/2014 5:08:09 PM -
This is a comment from internal tracking system.
<<<<<<
In this "German locale" case,
ShortDateFormat should be 'dd/MM/yyyy' in DelphiRTL system. 'dd.MM.yyyy' is INCORRECT
These '/' character is NOT a simple/plain character. it will be replaced with DateSeparator field in TFormatSetting
This '/' is one of date/time formatting meta character.

Delphi's Date/Time format system is NOT equal as Windows OS's formatting system.
>>>>>>

Server Response from: ETNACODE01