Forum: Ruby Time vs Datetime vs Date

33def21bd696e6c290c9f5fba47930c8?d=identicon&s=25 Daniel Mendler (Guest)
on 2008-03-15 18:30
(Received via mailing list)
Hi all,

why are there three different classes representing time? I think that is
a really bad spot in the ruby library, because Time and DateTime seem to
be incompatible to each other. For example in rails sql columns declared
as datetime are returned as time, so I had to convert them manually. It
doesn't seems to be consistent...

Daniel
Cf7cd97cdc8ed7d4ae92965b24f0dfad?d=identicon&s=25 Stefan Rusterholz (apeiros)
on 2008-03-16 02:05
Daniel Mendler wrote:
> Hi all,
>
> why are there three different classes representing time? I think that is
> a really bad spot in the ruby library, because Time and DateTime seem to
> be incompatible to each other. For example in rails sql columns declared
> as datetime are returned as time, so I had to convert them manually. It
> doesn't seems to be consistent...
>
> Daniel

IMO they all suck. I invite everybody with spare time and some ruby/C
knowledge to help me finish chronos
(http://butler.rubyforge.org/svn/Version%201.0/chro... -
missing are DST implementation, refactoring to use modules so that one
can use it with Gregiorian, Julian, Chinese, Discordian or whatever
calendar system he/she likes, C implementation of the math stuff for
gregorian even though the ruby implementation beats Date by around
factor 10, calendar - a mutable gregorian datetime object and some other
things).
Anyway, to answer your question: Time is a wrapper around Unix-Epoch.
Date (and DateTime) use rational and a "day zero" for storage. So Time
is faster but the upper and lower bounds are tied to epoch time (which
for 32bit epoch times is something around 1970-2040 - not even enough to
represent the birthsday of my parents) while Date (and DateTime) have an
almost infinite range  but are *terribly* slow. And both classes'
interfaces are less than stellar IMO.

Regards
Stefan
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Trans (Guest)
on 2008-03-16 02:33
(Received via mailing list)
On Mar 15, 9:05 pm, Stefan Rusterholz <apei...@gmx.net> wrote:
>
> IMO they all suck. I invite everybody with spare time and some ruby/C
> knowledge to help me finish chronos
> (http://butler.rubyforge.org/svn/Version%201.0/chro...
> missing are DST implementation, refactoring to use modules so that one
> can use it with Gregiorian, Julian, Chinese, Discordian or whatever
> calendar system he/she likes, C implementation of the math stuff for
> gregorian even though the ruby implementation beats Date by around
> factor 10, calendar - a mutable gregorian datetime object and some other
> things).

I would recommend finishing in Ruby first. Worry about C optimizations
later.

2 cents,
T.
Cf7cd97cdc8ed7d4ae92965b24f0dfad?d=identicon&s=25 Stefan Rusterholz (apeiros)
on 2008-03-16 02:46
Trans wrote:
> On Mar 15, 9:05 pm, Stefan Rusterholz <apei...@gmx.net> wrote:
>>
>> IMO they all suck. I invite everybody with spare time and some ruby/C
>> knowledge to help me finish chronos
>> (http://butler.rubyforge.org/svn/Version%201.0/chro...
>> missing are DST implementation, refactoring to use modules so that one
>> can use it with Gregiorian, Julian, Chinese, Discordian or whatever
>> calendar system he/she likes, C implementation of the math stuff for
>> gregorian even though the ruby implementation beats Date by around
>> factor 10, calendar - a mutable gregorian datetime object and some other
>> things).
>
> I would recommend finishing in Ruby first. Worry about C optimizations
> later.
>
> 2 cents,
> T.

Sure, why do you think I first wrote it completly in ruby anyway? :)
(prototyping)
I intend to have all C functionality in ruby too. Will enable it to run
on non-MRI easily.
C will be the very last step.

Regards
Stefan
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.