[REBOL] Re: add/subtract with date!
From: brett:codeconscious at: 15-Nov-2000 12:03
> This maybe confusing at first but comes in rather handy when you want to
> add a certain amount of months instead of days. The only thing I miss is
> the automatic conversion of negative month values to preceding years.
>
Yes it would be nice if that bug was fixed. Before that occurs here's a
workaround.
add-months: function [
"Offsets a date using a number of months (positive or negative)."
date [date!]
months [integer!]
] [result-date delta-years delta-months] [
delta-years: to-integer divide months 12
delta-months: remainder months 12
if lesser? delta-months 0 [
delta-years: subtract delta-years 1
delta-months: add delta-months 12
]
result-date: date
result-date/year: add result-date/year probe delta-years
result-date/month: add result-date/month probe delta-months
return result-date
]
Brett.