#2626 sys::Date#plus question

fraya Thu 10 Aug 2017

In sys::Date#plus says:

Date plus(Duration days)

Add the specified number of days to this date to get a date in the future. 
Throw ArgErr if days parameter it not an even number of days.


Date(2008, Month.feb, 28) + 2day  =>  2008-03-01

Why an ArgErr if days is an odd number?

In sys/java/fan/sys/Date.java I see that it is checked

private Date plus(long ticks)
  // check even number of days
   if (ticks % Duration.nsPerDay != 0)
     throw ArgErr.make("Duration must be even num of days");


fansh> Date(2008, Month.feb, 28) + 1day        
fansh> Date.today + 1day

Can someone explain me what happens? Thank you

SlimerDude Thu 10 Aug 2017

Hi Fraya, I've noticed that description before, and it's an odd use of the English language. It just means, whole number of days, as in:

Throw ArgErr if days parameter it not a whole number of days.

Because the class is a Date, it doesn't make sense to add 3 hours to it; only multiple of days.

Hope this makes sense?

fraya Thu 10 Aug 2017

My fault. I'm very much obliged to you for improving my English :)

SlimerDude Mon 14 Aug 2017

Docs updated, see this commit.

Login or Signup to reply.