[fpc-pascal] StrToDate bug?

Bart bartjunk64 at gmail.com
Sat May 10 14:55:51 CEST 2014


Hi,

I'm using fpc 2.6.4.

While i was playing a bit with issue
http://bugs.freepascal.org/view.php?id=20522 I stmbled upon unexpected
behaviour of StrToDate function.

StrToDate('6-12-2011 ') (note the space at the end) actually gives me 6-12-2014.

=======================
program stodate;

{$mode objfpc}{$H+}
//{$mode delphi} behaves the same

uses
  Classes, SysUtils;

procedure TestStrToDate(DS: String);
var
  FS: TFormatSettings;
  DT: TDateTime;
  RetS: String;
begin
  FS := DefaultFormatSettings;
  FS.ShortDateFormat := 'd-M-yyyy';
  FS.LongDateFormat := 'dddd d MMMM yyyy';
  FS.DateSeparator := '-';
  if TryStrToDate(DS, DT, FS.ShortDateFormat, FS.DateSeparator) then
  begin
    RetS := DateToStr(DT, FS);
    write('"',DS,'" -> "',RetS,'"');
    if Trim(DS) <> RetS then writeln('  ?') else writeln;
  end;
end;

procedure RunTestStrToDate;
begin
  TestStrToDate('6-12-2011');
  TestStrToDate('6-12-2011 ');
  TestStrToDate('6-12-2011  ');
  TestStrToDate('6-12-2011   ');
end;


begin
  RunTestStrToDate;
end.
================

Output with fpc 2.6.4
"6-12-2011" -> "6-12-2011"
"6-12-2011 " -> "6-12-2014"  ?
"6-12-2011  " -> "6-12-2014"  ?
"6-12-2011   " -> "6-12-2014"  ?

Output with Delphi7
"6-12-2011" -> "6-12-2011"
"6-12-2011 " -> "6-12-2011"
"6-12-2011  " -> "6-12-2011"
"6-12-2011   " -> "6-12-2011"

Could somebody test this with trunk to see if this has already been fixed?

Bart



More information about the fpc-pascal mailing list