TOPIC: date handling question
#920
date handling question 3 Years, 2 Months ago
Hello,

I would like to reopen once again message posted some time ago (http://68.178.135.44/forum/topic.asp?TOPIC_ID=249)

What should #20010531.Plus(months: 1) return?

I have case that some "money precept" have to be appointed every period (month/ quarter) the same day as "begin" precept, e.g.:

2007-01-15
2007-02-15
....
2007-12-15

if there is day 15 function date.Plus(months: 1) returns right result, but in case of day 31 looks like:
2007-01-31
2007-03-03
2007-03-31
2007-05-01
2007-05-31
....

So in this case i think that should be increased month and if there is day "out of range" should be rounded to first right (eg. 31,30,29 or 28)

What is your opinion ?

Marek
 
 
#921
Re:date handling question 3 Years, 2 Months ago
Marek Sandor wrote:
[...]
So in this case i think that should be increased month and if there is day "out of range" should be rounded to first right (eg. 31,30,29 or 28)

What is your opinion ?

Marek
Hi, I think you are right. Maybe this should be the correct behaviour, not the current one adopted by Suneido. Anyway you could always write your special version of Plus method and add it to the Dates class.
For example:

Code:

add1Month = function(olddate)
{
newdate = Date(year: olddate.Year(), month: olddate.Month() + 1, day: 1)
if (olddate.Day() > newdate.EndOfMonthDay())
newdate = newdate.Replace(day: newdate.EndOfMonthDay())
else
newdate = newdate.Replace(day: olddate.Day())
return newdate.NoTime()
}



add1Month(#20010531)
=> #20010630

Post edited by: Mauro, at: 2007/06/18 10:29
 
 
Mauro