Page 1 of 1

TFindFile v4.12 and invalid argument to date encode

PostPosted: April 2nd, 2013, 8:13 pm
by tls_43017
Kambiz,

I found a problem with TFindFile and thought you would like to know.

We received files from Canada where the file date is dd/mm/yyyy. We are in the USA the file date is mm/dd/yyyy.

We copied the files to ours servers and some of the file date got messed up. I had to put a try and except in the FileTimeToDateTime to process the files.

The error I am getting without the patch is “invalid argument to date encode”.

Is there a better way to address the error?

function FileTimeToDateTime(const FileTime: TFileTime): TDateTime;
var
LocalFileTime: TFileTime;
SystemTime: TSystemTime;
begin
try // added
FileTimeToLocalFileTime(FileTime, LocalFileTime);
FileTimeToSystemTime(LocalFileTime, SystemTime);
Result := SystemTimeToDateTime(SystemTime);
except // added
Result := StrToDateTime('01/01/1980 12:00:00'); // added
end; // added
end;

Re: TFindFile v4.12 and invalid argument to date encode

PostPosted: April 3rd, 2013, 5:26 pm
by Kambiz
None of the date/time related functions that are used in FindFile are culture sensitive. It sounds to me like some other kind of problem.
Could you please send me a sample file to check it out? And, what version of Delphi do you use?

Re: TFindFile v4.12 and invalid argument to date encode

PostPosted: April 4th, 2013, 12:50 am
by tls_43017
Kambiz,

I have attached a zip with the invalid dates. You may have to unzip them on a Linux or Windows server. I unzipped them on my Windows 8 PC and it reset the dates to 1/1/1980.

?) 12:40 AM 732 PERMIT.EXP
?) 12:40 AM 1,218 INTERMDO.WS
?) 12:40 AM 2,118 TRANS.ANA
?) 12:40 AM 3,987 MINISTER.WPM

Re: TFindFile v4.12 and invalid argument to date encode

PostPosted: April 15th, 2013, 4:21 pm
by Kambiz
Sorry for the delay in writing back.

With FindFile in Delphi 7 everything was fine.
But the timestamp of your files are really odd. I suppose they are belong to the era that OS's had nothing to do with time zones and 4-digit year. :)

Re: TFindFile v4.12 and invalid argument to date encode

PostPosted: April 17th, 2013, 11:33 pm
by tls_43017
Adding the try..except catches the bad date/time and allows the processing to continue.