[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Datetime
From:       Colin Bartlett <colinb2r () googlemail ! com>
Date:       2017-02-07 1:15:11
Message-ID: CAKtK3JrnG7-KP=7Og2U8b_-9bETyNiR03v0FCpcw+5gL2nw1=w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I know quite a bit about Date, DateTime, Time, albeit more from the Ruby
and C code than from the documentation, and I don't think this is an
unreasonable general question: there are quite a lot of methods in all
three classes, so I don't think I'd expect someone to compare all the
methods before asking a question like this.

I think it might be helpful if at the beginning of
http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html
http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html
it stated that Time always uses the Gregorian Calendar but Date and
DateTime allow you to use the Julian Calendar or a Julian Calendar which at
a date of your choice switches to the Gregorian Calendar.

So - subject to the caveat I end this post with - use Time if you only need
the Gregorian Calendar, and use DateTime if you need the Julian Calendar or
a calendar which starts as Julian and later switched to Gregorian.

That is what is being said here:
http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html
A subclass of Date
<http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html> that easily
handles date, hour, minute, second and offset.
...
So when should you use DateTime in Ruby and when should you use Time?
Almost certainly you'll want to use Time since your app is probably dealing
with current dates and times. However, if you need to deal with dates and
times in a historical context you'll want to use DateTime to avoid making
the same mistakes as UNESCO. If you also have to deal with timezones then
best of luck - just bear in mind that you'll probably be dealing with local
solar times <http://en.wikipedia.org/wiki/Solar_time>, since it wasn't
until the 19th century that the introduction of the railways necessitated
the need for Standard Time
<http://en.wikipedia.org/wiki/Standard_time#Great_Britain> and eventually
timezones.
...

So if for some reason you need a mixed Julian-Gregorian calendar which will
be used for both historical dates and times and for current dates and times
with timezones then neither Time nor DateTime will work.

Caveat: I think the answer isn't quite as simple as that DateTime
documentation implies, because there are some useful Date and DateTime
construction and singleton methods which aren't standard in Time. For
example: commercial, ordinal, leap?

[Attachment #5 (text/html)]

<div dir="ltr"><div><div>I know quite a bit about Date, DateTime, Time, albeit more \
from the Ruby and C code than from the documentation, and I don&#39;t think this is \
an unreasonable general question: there are quite a lot of methods in all three \
classes, so I don&#39;t think I&#39;d expect someone to compare all the methods \
before asking a question like this.<br><br></div></div><div>I think it might be \
helpful if at the beginning of<br><a \
href="http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html">http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html</a><br><a \
href="http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html">http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html</a><br></div><div>it \
stated that Time always uses the Gregorian Calendar but Date and DateTime allow you \
to use the Julian Calendar or a Julian Calendar which at a date of your choice \
switches to the Gregorian Calendar.<br><br></div><div>So - subject to the caveat I \
end this post with - use Time if you only need the Gregorian Calendar, and use \
DateTime if you need the Julian Calendar or a calendar which starts as Julian and \
later switched to Gregorian.<br><br></div><div>That is what is being said here:<br><a \
href="http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html">http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html<br></a>A \
subclass of <a href="http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html">Date</a> \
that easily handles date, hour, minute, second and offset.<br>...<br>So when should \
you use <code>DateTime</code> in Ruby and when should you use <code>Time</code>? \
Almost certainly you'll want to use <code>Time</code> since your app is probably \
dealing with current dates and times. However, if you need to deal with dates and \
times in a historical context you'll want to use <code>DateTime</code> to avoid \
making the same mistakes as UNESCO. If you also have to deal with timezones then best \
of luck - just bear in mind that you'll probably be dealing with <a \
href="http://en.wikipedia.org/wiki/Solar_time">local solar times</a>, since it wasn't \
until the 19th century that the introduction of the railways necessitated the need \
for <a href="http://en.wikipedia.org/wiki/Standard_time#Great_Britain">Standard \
Time</a> and eventually timezones.<br>...<br><br>So if for some reason you need a \
mixed Julian-Gregorian  calendar which will be used for both historical dates and \
times and for  current dates and times with timezones then neither Time nor DateTime 
will work.<br><br>Caveat: I think the answer isn&#39;t quite as simple as that \
DateTime documentation implies, because there are some useful Date and DateTime \
construction and singleton methods which aren&#39;t standard in Time. For example: \
commercial, ordinal, \
leap?<br><br></div><div><br><br></div><div><br><br><br><br></div></div>



Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic