Recent

Author Topic: Is this a Bug in TryStrToDate when useFormat = 'dddddd' or is it a 'feature'?  (Read 2092 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Run the following command-line program:

Code: Pascal  [Select][+][-]
  1. Program StrToDateBug;
  2. uses SysUtils;
  3.  
  4. Const
  5.     FullDateFormat = 'dddddd';
  6. var
  7.     S    : String;
  8.     D    : TDate;
  9.     Res : Boolean;
  10. Begin
  11.   D := Now;
  12.   S := FormatDateTime(FullDateFormat,D);
  13.   Writeln('Date of today is ' , S);
  14.   Res := TryStrToDate(S,D,FullDateFormat);
  15.   If Res
  16.   then Writeln('Date is valid')
  17.   else Writeln('Date is invalid');
  18.   Readln;
  19. End.
  20.  

Even though S is assigned the valid date from FormatDateTime, TryStrToDate returns an invalid response. I tracked the bug to the function IntStrToDate: It doesn't consider the case where the format is six 'd's (dddddd).

If it's a bug, I'd be happy to rewrite this routine, unless it was not meant to handle this format...  :)

ccrause

  • Hero Member
  • *****
  • Posts: 845
If it's a bug, I'd be happy to rewrite this routine, unless it was not meant to handle this format...  :)
According to the description of TryStrToDate:
Quote
The Date must consist of 1 to three digits
This means that 'd' and 'dd' should be acceptable in your example,  while 'ddd' up to 'dddddd' should not be acceptable. So not a bug in my opinion.

winni

  • Hero Member
  • *****
  • Posts: 3197
Hi!

I don't understand the question.

What do you want to achieve with 'dddddd'??

Something like  050505050505 for today?

Where is the use for that??

Perplexed

Winni


wp

  • Hero Member
  • *****
  • Posts: 11857
winni, tthe "six-d format" allows using the FormatSettings.LongDateFormat in FormatDateTime(): https://www.freepascal.org/docs-html/rtl/sysutils/formatchars.html

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   SysUtils;
  5. begin
  6.   WriteLn(FormatDateTime('dddddd', now));   // ---> "Freitag, 5. März 2021" (German language settings)
  7.   ReadLn;
  8. end.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
ScanDateTime might do the trick.
The StrToDate by design only handles numeric input AFAIK.

So, unless Delphi accepts such a string as input, we won't implement it in StrToDate function.

Bart

 

TinyPortal © 2005-2018