Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Converting between Time and DateTime
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 32 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Lloyd Zusman  
View profile  
 More options Nov 12 2005, 12:54 pm
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Sun, 13 Nov 2005 02:54:58 +0900
Local: Sat, Nov 12 2005 12:54 pm
Subject: Converting between Time and DateTime
What is the recommended method for converting between Time objects and
those of type DateTime?

I know that I can do this:

  dt = DateTime.new
  t = Time.mktime(dt.year, dt.mon, dt.day,
                  dt.hour, dt.min, dt.sec)

.. and this:

  t = Time.now
  dt = DateTime.civil(t.year, t.mon, t.day,
                      t.hour, t.min, t.sec)

However, this seems overly verbose to me, and I end up putting one or
both of the following into my ruby programs:

  class DateTime
    def self.fromTime(t)
      return DateTime.civil(t.year, t.mon, t.day,
                            t.hour, t.min, t.sec)
    end
  end

  class Time
    def self.fromDateTime(dt)
      return Time.mktime(dt.year, dt.mon, dt.day,
                         dt.hour, dt.min, dt.sec)
    end
  end

Is there any reason for why we can't have similar methods as part of the
official DateTime and Time classes?

Or is there already some sort of mechanism for this that I have
overlooked?

Thanks in advance.

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Nov 12 2005, 1:26 pm
Newsgroups: comp.lang.ruby
From: "David A. Black" <dbl...@wobblini.net>
Date: Sun, 13 Nov 2005 03:26:07 +0900
Local: Sat, Nov 12 2005 1:26 pm
Subject: Re: Converting between Time and DateTime
Hi --

On Sun, 13 Nov 2005, Lloyd Zusman wrote:
> What is the recommended method for converting between Time objects and
> those of type DateTime?

This is probably just a stepping-stone on the way to something more
elegant... but try this:

   require 'date'
   require 'time'

   t = Time.parse(DateTime.new.sec.to_s)

(Could we get all the time/date stuff unified and loaded by default?
Is that too much overhead?)

David

--
David A. Black
dbl...@wobblini.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Nov 12 2005, 1:28 pm
Newsgroups: comp.lang.ruby
From: "David A. Black" <dbl...@wobblini.net>
Date: Sun, 13 Nov 2005 03:28:32 +0900
Local: Sat, Nov 12 2005 1:28 pm
Subject: Re: Converting between Time and DateTime
Hi --

On Sun, 13 Nov 2005, David A. Black wrote:
> Hi --

> On Sun, 13 Nov 2005, Lloyd Zusman wrote:

>> What is the recommended method for converting between Time objects and
>> those of type DateTime?

> This is probably just a stepping-stone on the way to something more
> elegant... but try this:

>  require 'date'
>  require 'time'

>  t = Time.parse(DateTime.new.sec.to_s)

Withdrawn :-)

Completely wrong.  Sorry.

David

--
David A. Black
dbl...@wobblini.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Nov 12 2005, 1:35 pm
Newsgroups: comp.lang.ruby
From: "David A. Black" <dbl...@wobblini.net>
Date: Sun, 13 Nov 2005 03:35:11 +0900
Local: Sat, Nov 12 2005 1:35 pm
Subject: Re: Converting between Time and DateTime
Hi --

On Sun, 13 Nov 2005, Lloyd Zusman wrote:
> What is the recommended method for converting between Time objects and
> those of type DateTime?

OK, let me try again.

   irb(main):068:0> t = Time.now
   => Sat Nov 12 13:33:08 EST 2005
   irb(main):069:0> d = DateTime.parse(t.iso8601)
   => #<DateTime: 52999645097/21600,-5/24,2299161>
   irb(main):070:0> d.strftime("%c")
   => "Sat Nov 12 13:33:08 2005"
   irb(main):071:0> Time.parse(d.strftime("%c"))
   => Sat Nov 12 13:33:08 EST 2005

'parse' seems to be a good bet in both directions.

David

--
David A. Black
dbl...@wobblini.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 12 2005, 1:49 pm
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Sun, 13 Nov 2005 03:49:50 +0900
Local: Sat, Nov 12 2005 1:49 pm
Subject: Re: Converting between Time and DateTime
"David A. Black" <dbl...@wobblini.net> writes:

Yes, I thought of these, but they involve converting to and from an
intermediate String object.  The ones I suggested in my original message
are more direct ... although they each require six subsidiary method
calls.

If I get some extra time, I'll benchmark my versions against these
intermediate-String versions.  But no matter which is faster, wouldn't
it ultimately be better if we had conversion methods built in to the
standard classes?  Even if we don't unify Time with DateTime, these
extra contstructors would be a nice convenience.

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Schierbeck  
View profile  
 More options Nov 12 2005, 2:22 pm
Newsgroups: comp.lang.ruby
From: Daniel Schierbeck <daniel.schierb...@gmail.com>
Date: Sat, 12 Nov 2005 20:22:56 +0100
Local: Sat, Nov 12 2005 2:22 pm
Subject: Re: Converting between Time and DateTime

I think this would be more Rubyish:

   class DateTime
     def to_time
       Time.mktime(year, mon, day, hour, min, sec)
     end
   end

   class Time
     def to_datetime
       DateTime.civil(year, mon, day, hour, min, sec)
     end
   end

I haven't tested it, but it should work.

Cheers,
Daniel


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 13 2005, 10:45 am
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Mon, 14 Nov 2005 00:45:30 +0900
Local: Sun, Nov 13 2005 10:45 am
Subject: Re: Converting between Time and DateTime

Thanks.  Is this considered more ruby-ish because of the non-camel-case
of the method names? ... or because of the to_* methods instead of the
from* constructors? ... or both?

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kirk Haines  
View profile  
 More options Nov 13 2005, 10:46 am
Newsgroups: comp.lang.ruby
From: Kirk Haines <khai...@enigo.com>
Date: Mon, 14 Nov 2005 00:46:51 +0900
Local: Sun, Nov 13 2005 10:46 am
Subject: Re: Converting between Time and DateTime
On Saturday 12 November 2005 10:54 am, Lloyd Zusman wrote:

> Is there any reason for why we can't have similar methods as part of the
> official DateTime and Time classes?

> Or is there already some sort of mechanism for this that I have
> overlooked?

You have not overlooked anything.

In my standard set of extensions are these:

class Time
        def to_date
                Date.new(year, month, day)
                rescue NameError
                nil
        end

        def to_datetime
                DateTime.new(year, month, day, hour, min, sec)
                rescue NameError
                nil
        end
end

class DateTime
        def to_time
                Time.local(year,month,day,hour,min,sec)
        end
end

class Date
        def to_time
                Time.local(year,month,day)
        end
end

Kirk Haines


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kirk Haines  
View profile  
 More options Nov 13 2005, 10:55 am
Newsgroups: comp.lang.ruby
From: Kirk Haines <khai...@enigo.com>
Date: Mon, 14 Nov 2005 00:55:36 +0900
Local: Sun, Nov 13 2005 10:55 am
Subject: Re: Converting between Time and DateTime
On Saturday 12 November 2005 11:26 am, David A. Black wrote:

> (Could we get all the time/date stuff unified and loaded by default?
> Is that too much overhead?)

I don't know if that is practical.  Time and Date/DateTime use two entirely
different mechanisms for keeping track of the passage of time.  Time utilizes
seconds since the start of 1970 -- standard Unix time tracking.

Date/DateTime uses keeps tracks of days and fractions of days using Rational,
and it's start of time is about the start of the year in 4712 B.C.

They are quite different, and while one should not have to write one's own
code to convert from one to another -- all three classes should be patched to
allow each conversion from one to another -- they should stay separate.

Kirk Haines


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kirk Haines  
View profile  
 More options Nov 13 2005, 11:03 am
Newsgroups: comp.lang.ruby
From: Kirk Haines <khai...@enigo.com>
Date: Mon, 14 Nov 2005 01:03:49 +0900
Local: Sun, Nov 13 2005 11:03 am
Subject: Re: Converting between Time and DateTime
On Saturday 12 November 2005 11:35 am, David A. Black wrote:

> OK, let me try again.

>    irb(main):068:0> t = Time.now
>    => Sat Nov 12 13:33:08 EST 2005
>    irb(main):069:0> d = DateTime.parse(t.iso8601)
>    => #<DateTime: 52999645097/21600,-5/24,2299161>
>    irb(main):070:0> d.strftime("%c")
>    => "Sat Nov 12 13:33:08 2005"
>    irb(main):071:0> Time.parse(d.strftime("%c"))
>    => Sat Nov 12 13:33:08 EST 2005

> 'parse' seems to be a good bet in both directions.

It works in both directions because the underlying 'parse' is the same
one.  :)

They all use the same the Date#_parse method defined in date/format.rb.

Using this is going to be much slower than just doing conversions with the
numerical values and constructor methods that the classes provide.

Kirk Haines


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Nov 13 2005, 11:06 am
Newsgroups: comp.lang.ruby
From: "David A. Black" <dbl...@wobblini.net>
Date: Mon, 14 Nov 2005 01:06:46 +0900
Local: Sun, Nov 13 2005 11:06 am
Subject: Re: Converting between Time and DateTime
Hi --

I guess what I'm thinking of mostly is default loading.  It seems a
little odd to see this:

   irb(main):002:0> Time
   => Time
   irb(main):003:0> require 'time'
   => true

and, in general, to have to know what you can do before you load
things and what you can only do after.  Not so much reducing the three
classes to one, then, but streamlining the way it all works.

David

--
David A. Black
dbl...@wobblini.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 13 2005, 11:07 am
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Mon, 14 Nov 2005 01:07:26 +0900
Local: Sun, Nov 13 2005 11:07 am
Subject: Re: Converting between Time and DateTime

Kirk Haines <khai...@enigo.com> writes:
> On Saturday 12 November 2005 10:54 am, Lloyd Zusman wrote:

>> Is there any reason for why we can't have similar methods as part of the
>> official DateTime and Time classes?

>> Or is there already some sort of mechanism for this that I have
>> overlooked?

> You have not overlooked anything.

Oh well ... (sigh)

And thanks.

In your methods below, I see "rescue" without a formal "begin/end"
block.  I've never seen that construct before.  I'm guessing that single
line statements don't need begin/end, correct?

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ts  
View profile  
 More options Nov 13 2005, 11:36 am
Newsgroups: comp.lang.ruby
From: ts <dec...@moulon.inra.fr>
Date: Mon, 14 Nov 2005 01:36:05 +0900
Local: Sun, Nov 13 2005 11:36 am
Subject: Re: Converting between Time and DateTime

>>>>> "L" == Lloyd Zusman <l...@asfast.com> writes:

L> In your methods below, I see "rescue" without a formal "begin/end"
L> block.  I've never seen that construct before.  I'm guessing that single
L> line statements don't need begin/end, correct?

 no, no : this is a difference 1.4 and 1.6. Since 1.6 you can write

   def aa
      # any lines
   rescue XXX
      # any lines
   rescue YYY
      # any lines
   # ...
   else
      # any lines
   ensure
      # any lines
   end

 this is only with 1.6.3 that it work also with singleton methods.

 Single line statements are

   xxx rescue yyy

 which is like

   begin
      xxx
   rescue
      yyy
   end

Guy Decoux


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Nov 13 2005, 11:36 am
Newsgroups: comp.lang.ruby
From: "David A. Black" <dbl...@wobblini.net>
Date: Mon, 14 Nov 2005 01:36:55 +0900
Local: Sun, Nov 13 2005 11:36 am
Subject: Re: Converting between Time and DateTime
Hi --

On Mon, 14 Nov 2005, Lloyd Zusman wrote:
> In your methods below, I see "rescue" without a formal "begin/end"
> block.  I've never seen that construct before.  I'm guessing that single
> line statements don't need begin/end, correct?

Method defs provide an implicit 'begin', so you can put a rescue
clause in them without adding a 'begin'.

David

--
David A. Black
dbl...@wobblini.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Schierbeck  
View profile  
 More options Nov 13 2005, 11:42 am
Newsgroups: comp.lang.ruby
From: Daniel Schierbeck <daniel.schierb...@gmail.com>
Date: Sun, 13 Nov 2005 17:42:28 +0100
Local: Sun, Nov 13 2005 11:42 am
Subject: Re: Converting between Time and DateTime

Both. It also allows you to do something like this:

   def some_time_method(time)
     time = time.to_time  # now we know we have a Time object
   end

   some_time_method(DateTime.new(...))

That way you can use a DateTime object instead of a Time object and have
it automatically converted. Otherwise, you'd have to do this:

   some_time_method(Time.from_datetime(DateTime.new(...)))

Cheers,
Daniel


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Schierbeck  
View profile  
 More options Nov 13 2005, 12:14 pm
Newsgroups: comp.lang.ruby
From: Daniel Schierbeck <daniel.schierb...@gmail.com>
Date: Sun, 13 Nov 2005 18:14:48 +0100
Local: Sun, Nov 13 2005 12:14 pm
Subject: Re: Converting between Time and DateTime
For the record, I'm using this code:

class DateTime
   def to_time
     Time.mktime(year, month, day, hour, min, sec)
   end

   def to_datetime
     return self
   end
end

class Date
   def to_time
     Time.mktime(year, month, day)
   end

   def to_datetime
     to_time.to_datetime
   end

   def to_date
     return self
   end
end

class Time
   def to_date
     Date.new(year, month, day)
   end

   def to_datetime
     DateTime.civil(year, month, day, hour, min, sec)
   end

   def to_time
     return self
   end
end


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 13 2005, 12:21 pm
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Mon, 14 Nov 2005 02:21:58 +0900
Local: Sun, Nov 13 2005 12:21 pm
Subject: Re: Converting between Time and DateTime

Got it.  Thanks!

So now, all we need is to have a few to_* conversion methods added to
the standard Time, DateTime, and Date classes so that we all don't have
to keep re-inventing this. :)

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 13 2005, 12:22 pm
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Mon, 14 Nov 2005 02:22:08 +0900
Local: Sun, Nov 13 2005 12:22 pm
Subject: Re: Converting between Time and DateTime

ts <dec...@moulon.inra.fr> writes:
>>>>>> "L" == Lloyd Zusman <l...@asfast.com> writes:

> L> In your methods below, I see "rescue" without a formal "begin/end"
> L> block.  I've never seen that construct before.  I'm guessing that single
> L> line statements don't need begin/end, correct?

>  no, no : this is a difference 1.4 and 1.6. Since 1.6 you can write

>  [ ... etc. ... ]

Ah ... thanks for the clarification.

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lloyd Zusman  
View profile  
 More options Nov 13 2005, 12:32 pm
Newsgroups: comp.lang.ruby
From: Lloyd Zusman <l...@asfast.com>
Date: Mon, 14 Nov 2005 02:32:02 +0900
Local: Sun, Nov 13 2005 12:32 pm
Subject: Re: Converting between Time and DateTime
"David A. Black" <dbl...@wobblini.net> writes:

> Hi --

> On Mon, 14 Nov 2005, Lloyd Zusman wrote:

>> In your methods below, I see "rescue" without a formal "begin/end"
>> block.  I've never seen that construct before.  I'm guessing that single
>> line statements don't need begin/end, correct?

> Method defs provide an implicit 'begin', so you can put a rescue
> clause in them without adding a 'begin'.

I never realized this.  I guess I overlooked that part of the docs.
This will allow me to remove a few begin/end constructs from some of the
short methods I've written.

Thanks.

--
 Lloyd Zusman
 l...@asfast.com
 God bless you.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Schierbeck  
View profile  
 More options Nov 13 2005, 12:39 pm
Newsgroups: comp.lang.ruby
From: Daniel Schierbeck <daniel.schierb...@gmail.com>
Date: Sun, 13 Nov 2005 18:39:20 +0100
Local: Sun, Nov 13 2005 12:39 pm
Subject: Re: Converting between Time and DateTime

Yeah, but only if there's a strong enough sentiment in the community. No
reason to add to the standard library unless the functionality is really
needed.

Cheers,
Daniel


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
 
View profile  
 More options Nov 14 2005, 10:33 am
Newsgroups: comp.lang.ruby
From: Steven Grady From: <gr...@scam.XCF.Berkeley.EDU>
Date: Mon, 14 Nov 2005 15:33:20 +0000 (UTC)
Local: Mon, Nov 14 2005 10:33 am
Subject: Re: Converting between Time and DateTime

Daniel Schierbeck <daniel.schierb...@gmail.com> writes:
>Lloyd Zusman wrote:
>> So now, all we need is to have a few to_* conversion methods added to
>> the standard Time, DateTime, and Date classes so that we all don't have
>> to keep re-inventing this. :)

>Yeah, but only if there's a strong enough sentiment in the community. No
>reason to add to the standard library unless the functionality is really
>needed.

Well, as it turns out, last week I spent about an hour looking for
these conversion functions (using ri, the pickaxe book, etc.), before
realizing they weren't part of the standard library and writing them myself.
Another reason to add to the standard library is if something is so natural
that is confusing to _not_ find it there.
--
        Steven
        gr...@xcf.berkeley.edu
"Bobby, if you weren't my son, I'd hug you."

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Sanderson  
View profile  
 More options Nov 14 2005, 1:07 pm
Newsgroups: comp.lang.ruby
From: "Adam Sanderson" <netgh...@gmail.com>
Date: 14 Nov 2005 10:07:11 -0800
Local: Mon, Nov 14 2005 1:07 pm
Subject: Re: Converting between Time and DateTime
Is there any reason to choose one over the other?   At least for post
1970 dates?  I've always found Time's API a little easier to use.

Anyone have thoughts on when one would want to use DateTime vs Time?
  .adam sanderson


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kirk Haines  
View profile  
 More options Nov 14 2005, 1:47 pm
Newsgroups: comp.lang.ruby
From: Kirk Haines <khai...@enigo.com>
Date: Tue, 15 Nov 2005 03:47:03 +0900
Local: Mon, Nov 14 2005 1:47 pm
Subject: Re: Converting between Time and DateTime
On Monday 14 November 2005 11:12 am, Adam Sanderson wrote:

> Is there any reason to choose one over the other?   At least for post
> 1970 dates?  I've always found Time's API a little easier to use.

> Anyone have thoughts on when one would want to use DateTime vs Time?

The range is one difference.  If you want to represent 376 AD, you can't use
Time.

Time will be faster, since DateTime uses Rational for everything.  DateTime's
units are days and fractions of days.  That might make a difference to you,
or it might not.  If you are doing a lot of date conversion or date math, you
might find DateTime easier to use.

Hmmm.  It's a good question, and I don't have as good an answer as you want,
probably.

Personally, I use Time unless I am dealing with date ranges that go beyond
what Time handles, as a general rule.

Kirk Haines


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sam Gentle  
View profile  
 More options Nov 15 2005, 1:51 am
Newsgroups: comp.lang.ruby
From: Sam Gentle <sgen...@gmail.com>
Date: Tue, 15 Nov 2005 15:51:16 +0900
Local: Tues, Nov 15 2005 1:51 am
Subject: Re: Converting between Time and DateTime
On 11/15/05, Kirk Haines <khai...@enigo.com> wrote:

> On Monday 14 November 2005 11:12 am, Adam Sanderson wrote:
> > Is there any reason to choose one over the other?   At least for post
> > 1970 dates?  I've always found Time's API a little easier to use.

> > Anyone have thoughts on when one would want to use DateTime vs Time?

> The range is one difference.  If you want to represent 376 AD, you can't use
> Time.

> Time will be faster, since DateTime uses Rational for everything.  DateTime's
> units are days and fractions of days.  That might make a difference to you,
> or it might not.  If you are doing a lot of date conversion or date math, you
> might find DateTime easier to use.

Sounds a bit to me like the difference between Fixnum and Bignum...

Sam


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Pine  
View profile  
 More options Nov 15 2005, 7:44 am
Newsgroups: comp.lang.ruby
From: Chris Pine <ch...@pine.fm>
Date: Tue, 15 Nov 2005 21:44:05 +0900
Local: Tues, Nov 15 2005 7:44 am
Subject: Re: Converting between Time and DateTime

> Sounds a bit to me like the difference between Fixnum and Bignum...

Except that those convert to the one you want automatically, and have
a common superclass (Integer), and just generally play together
nicely.

I *wish* Time and DateTime worked more like Fixnum and Bignum.

Chris


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 32   Newer >
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google