PDA

View Full Version : DateTime functions



Peter van Mil
2-Dec-2015, 01:38 PM
The new DateTime functions are great. Today I had a February 29 problem and I have checked how the new functions work.

If you add three years to the date 02/29/2012 you get 02/29/2015 without an error. If you add one day to this invalid date you get an error.

This isn't a big issue, but I should say the a date like 02/29/2015 shouldn't be accepted (= generate an error).




Procedure OnClick
DateTime dtDate
Integer iYear iMonth iDay

Move 2012 to iYear
Move 2 to iMonth
Move 29 to iDay

Move (DateSet(iYear, iMonth, iDay)) to dtDate
Showln dtDate

Move (DateAddYear(dtDate, 3)) to dtDate
Showln dtDate
Move (DateAddDay(dtDate, 1)) to dtDate
Showln dtDate
End_Procedure

Samuel Pizarro
2-Dec-2015, 03:32 PM
Hummm

in this case when adding a datespan to a valid date the function dateaddyear should return the first previous valid date and not just fail.
in this case should return 2015-02-28.

now if one tries to set a date with dateset function using invalid components than in this case I agree in returning an error.

But if you have originally a valid timestamp and you are adding/subtracting valid timespans components it should never raise an error, but return the next or previous valid timestamp values.

One can arguee that it should return the NEXT valid timestamp instead of the PREVIOUS one. So those functions should have a third optional parameter to pass -1 or +1 to handle that cases.

Just my 2 or maybe 10 cents.

John Tuohy
2-Dec-2015, 03:47 PM
That's a bug. It should have adjusted your day down to 28.

Thanks for the report - next build.

-John