Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
RTL
Delphi
Arithmetic
ConvUtils
Date - Time
DateUtils
File Management
Format + Float
Input/Output
Math Unit
Memory, Pointer, Address
Null-terminated strings
Other Classes
Other RTL
Pascal Strings
Regular Expressions
RTL Exceptions
Text Files
Thread support
Typed/Untyped Files
WinAPI
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/RTL/Delphi/DateUtils
[ Add a report in this area ]
Report #:
104942
Status:
Open
FormatSettings ShortDateFormat and LongDateFormat contains wrong values
Project:
Delphi
Build #:
16.0.4429.46931
Version:
16.4
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:
5/18/2012 5:40:56 AM
Platform:
All versions
Internal Tracking #:
28331
Resolution:
None
(Resolution Comments)
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
13
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;
//-------------------------------------------------------
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us