FormatDate with invalid date

Post bugreports for the Windows version here
BarryG
Addict
Addict
Posts: 1520
Joined: Thu Apr 18, 2019 8:17 am

FormatDate with invalid date

Post by BarryG »

(1) The manual says that FormatDate() returns -1 on failure, but -1 for a string return value? I'd rather it return an empty string.

(2) Also, it doesn't return -1 for invalid dates anyway, as shown below.

Code: Select all

Debug FormatDate("%hh:%ii:%ss",Date(0,0,0,0,0,0)) ; Returns "0-:0-:0-" instead of "-1"
Here's my current workaround (which takes dashes in the mask into account):

Code: Select all

Procedure.s FormatDateEx(mask$,date.q)
  d$=FormatDate(mask$,date)
  If ParseDate(mask$,d$)=-1
    d$=""
  EndIf
  ProcedureReturn d$
EndProcedure

Debug FormatDateEx("%hh:%ii:%ss -1 test",Date(0,0,0,0,0,0)) ; Invalid, so returns "" instead of "0-:0-:0-"
Debug FormatDateEx("%hh:%ii:%ss -1 test",Date()) ; Valid, so returns the correct formatted string.