Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Question about date? function

From: carl:cybercraft at: 13-Oct-2001 20:02

On 13-Oct-01, Brock & Janet wrote:
> Should the date? function return false if an invalid date is > entered? > For example, when entering (YYYY-MM-DD); >>> date? 2001-12-25 > == true > So you would think that a False would be returned if a date was > incorrect, however, unexpectedly; >>> date? 2001-13-25 > ** Syntax Error: Invalid date -- 2001-13-25 > ** Near: (line 1) date? 2001-13-25 > Since date? doesn't return a false but a Syntax Error. When I try > the following I would expect it to gracefully allow me to enter an > invalid date and allow me to write code around it to correct it. >>> if error? try [ date? 2001-13-25] [print "An invalid date was >>> entered"] > ** Syntax Error: Invalid date -- 2001-13-25 > ** Near: (line 1) error? try [ date? 2001-13-25] > Any thoughts?
I'd think the error occurs because it's an invalid datatype, same as entering...
>> 100s
** Syntax Error: Invalid integer -- 100s is invalid. When a script's running though, any dates entered would probably start out as a string, so just check for an error when converting it to a date...
>> if error? try [to-date "2001-13-25"][print "Date error!"]
Date error! -- Carl Read