[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

dates earlier than 1970?

Kevin Howe

11/3/2004 7:28:00 PM

I have a web app that collects new employee info, one of the fields being
"Birth date". However since many of the employees were born earlier than
1970 I am unable to turn these into Ruby Time/Date objects. Is there a ruby
library that can handle dates earlier than 1970?


2 Answers

Jamis Buck

11/3/2004 7:44:00 PM

0

Kevin Howe wrote:
> I have a web app that collects new employee info, one of the fields being
> "Birth date". However since many of the employees were born earlier than
> 1970 I am unable to turn these into Ruby Time/Date objects. Is there a ruby
> library that can handle dates earlier than 1970?

String? I honestly don't mean that facetiously, either. If you enforce
the right format on the strings, you can do date-wise comparisons on
them, and extract date-part info via regexps:

"1964-07-25" < "1974-07-25"
year = "1964-07-25".match(/^(\d\d\d\d)-/ )[1].to_i

Certainly, the above could benefit from a minimal wrapper around it to
make things like date-part extraction less cumbersome. But for most of
the things I use dates for, strings suffice.

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...


Yukihiro Matsumoto

11/3/2004 7:47:00 PM

0

Hi,

In message "Re: dates earlier than 1970?"
on Thu, 4 Nov 2004 04:28:46 +0900, "Kevin Howe" <khowe@perfnet.ca> writes:

|I have a web app that collects new employee info, one of the fields being
|"Birth date". However since many of the employees were born earlier than
|1970 I am unable to turn these into Ruby Time/Date objects. Is there a ruby
|library that can handle dates earlier than 1970?

(1) If your platform handles negative time_t, Time can be as old as
1902, which might be long enough to represent _most_ of employees'
birth date. Try Time.at(1965, 4, 14) for example.

(2) Date class can represent arbitrary date on the calendar, even back
to 4713 B.C, which covers, as I believe, _all_ employees.
Just require "date".

matz.