Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Date - Time    [ Add a report in this area ]  
Report #:  134629   Status: Closed
XE10: DateSeparator is default '/' instead of locale separator
Project:  Delphi Build #:  23.0.20618.2753
Version:    21.0 Submitted By:   Robert Cerny
Report Type:  Basic functionality failure Date Reported:  11/2/2015 6:17:20 AM
Severity:    Commonly encountered problem Last Updated: 12/15/2015 3:02:56 AM
Platform:    All platforms Internal Tracking #:   72851
Resolution: Duplicate (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
https://msdn.microsoft.com/en-us/library/windows/desktop/dd373837%28v=vs.85%29.aspx

GetLocaleChar assumes one char result, according to documentation it can be up to 4 chars.
Default short date format for slovenian locale is "dd. mm. yy", so the dateseparator would be ". "
In this case GetLocaleInfo returns error "The data area passed to a system call is too small." and GetLocaleChar returns default '/'.

Another problem: Dateseparator is not necessarily a single uniform separator charachter.
LOCALE_SDATE constant is deprecated, so scandate() should use shortdateformat to unformat input string.
Steps to Reproduce:
Set short date format to "dd. mm. yy"
Run following code:
var
  S: string;
  D: TDateTime;
begin
  S := DateTimeToStr(Now);
  D := StrToDatetime(S);//error
end;
Workarounds
function MyGetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char;
var
  Buffer: array[0..3] of Char;
begin
  if GetLocaleInfo(Locale, LocaleType, Buffer, 4) > 0 then
    Result := Buffer[0] else
    Result := Default;
end;

initialization
  RWPatchCode(OldGetLocaleChar, @sysutils.GetLocaleChar, @MyGetLocaleChar);
finalization
  RWUnPatchCode(OldGetLocaleChar);
end;
Attachment
None
Comments

None

Server Response from: ETNACODE01