Re: Duration

Marnen Laibow-Koser
Tue, 21 Dec 2010 20:56:37 -0000

Jack Waugh wrote in post #969867:
> It looks as though if you ask a DateTime to add something to itself,
> it looks at the something, and if it''s an integer, it interprets
it as
> a duration in seconds, but if it''s a Rational, it interprets it as
a
> duration in days.
>
> It''s inconsistent.  Why didn''t the designers settle on
one type for
> durations and one way to interpret them?

Adding a dimensionless number to a measurement with units is asking for
trouble.  Just specify units and you''ll be fine.

> What should one store in a
> database for a duration?

Anything you like.  Use composed_of if necessary.

>  What rules should one follow to avoid being
> tripped up by numbers being interpreted as different measures
> depending on accidental features such as the numbers''
> representations?

Use units.

>  This is very disappointing; engineering designs
> should make logical sense.

It makes lots of sense to specify units (and as Fred said, 1.hour is a
Duration, not a Fixnum).   What doesn''t make sense is expecting the sum
of a Time and a Fixnum to be anything but undefined.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org

Sent from my iPhone

--
Posted via http://www.ruby-forum.com/.