Date::Delta

S

Sebastian Krause

I ran across a pretty non-intuitive (IMHO) behavior with Date::Delta
Objects.

irb(main):001:0> require 'date/delta'
=> true
irb(main):002:0> d = Date.today - Date.today + Date::Delta.months(1)
=> ((0/1)+(1/1)*i)
irb(main):003:0> d.class
=> Complex


Okay, I figured out where this came from:
Date::Delta is implemented via the linear map

1 day -> 1
1 month -> i

from the timedeltas to the complex numbers.
It's because the length of one month is different depending on where it
is added.
The multiplication of complex numbers is irrelevant here.

So isn't it strange that this implementation detail comes up when doing
arithmetic with times? Would it be better if #<Date::Delta: +(0d
00:00'00"000)+(0y 1m) (0/1+1/1i)>
were returned?

What does everyone else think?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top