Today I was trying something out in my Rails console and this happened,
2.0.0p247 :009 > Date.today -29.days
=> Fri, 07 Feb 2014
2.0.0p247 :010 > Date.today - 29.days
=> Thu, 09 Jan 2014
I am pretty baffled. I can see that I am missing something basic. But it just inst striking my mind! Could anyone explain why this is happening?
What actually happens is this:
Date.today(-29.days) # => Fri, 07 Feb 2014
today
has an optional parameter called start
, which defaults to Date::ITALY
.
An optional argument the day of calendar reform (start) as a Julian day number, which should be 2298874 to 2426355 or -/+oo. The default value is Date::ITALY (2299161=1582-10-15).
Passing -29.days
to today
apparently has no effect.
Whereas:
Date.today + -29.days # => Thu, 09 Jan 2014
Which is the same as:
Date.today - 29.days # => Thu, 09 Jan 2014
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With