Date/time arithmetic is relatively straightforward and should normally produce the expected results. However with leap years and months with different lengths, the situation can be confusing; this section will clarify how Qore does date arithmetic considering these special cases.
Adding or subtracting years and months (ex: $date += 2Y + 3M) will give you the same day on the desired month in the desired year. If the target month has fewer days than the source month, then you will get the last day of the month in that year. For example:
2004-02-29 - 1Y = 2003-02-28
Adding or subtracting days means adding or subtracting 24h periods; i.e. you will get the same time in the result of subtracting days, for example:
2004-02-29T10:15:00 - 10D = 2004-02-19T10:15:00
Subtracting one absolulte date from another will result in a relative date, normalized to the day value (that is, milliseconds over 999 are converted to seconds, seconds over 59 to minutes, minutes over 59 to hours, hours over 23 to days; months and years will not appear in the result as they do not indicate a fixed period of time but rather can vary in length depending on the absolute date/time starting point. For example:
$diff = 2007-02-29T10:15:03.255 - 2004-02-29T10:14:02.100; printf("%n\n", $diff)
Results in:
<time: 1096 days 1 minute 1 second 155 milliseconds>
To find the difference in seconds between two dates, convert each date value to an integer and subtract as follows:
int(2004-02-29) - int(2004-02-28) = 86400
Qore has no time zone support and therefore all date/time values are timezone agnostic. In particular, Daylight Savings Time is not taken into effect with date arithmetic. For this reason a day in Qore is always exactly 24 hours long.
Qore is capable of representing and performing calculations on dates before the adoption of the Gregorian calendar (proposed in 1582 and adopted at various times in Europe after this point). However all calculations are made as if the Gregorian calendar were always in effect (Qore implements a proleptic Gregorian calendar).