S
Sebastian Krause
I ran across a pretty non-intuitive (IMHO) behavior with Date:elta
Objects.
irb(main):001:0> require 'date/delta'
=> true
irb(main):002:0> d = Date.today - Date.today + Date:elta.months(1)
=> ((0/1)+(1/1)*i)
irb(main):003:0> d.class
=> Complex
Okay, I figured out where this came from:
Date:elta 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:elta: +(0d
00:00'00"000)+(0y 1m) (0/1+1/1i)>
were returned?
What does everyone else think?
Objects.
irb(main):001:0> require 'date/delta'
=> true
irb(main):002:0> d = Date.today - Date.today + Date:elta.months(1)
=> ((0/1)+(1/1)*i)
irb(main):003:0> d.class
=> Complex
Okay, I figured out where this came from:
Date:elta 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:elta: +(0d
00:00'00"000)+(0y 1m) (0/1+1/1i)>
were returned?
What does everyone else think?