dates earlier than 1970?

K

Kevin Howe

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?
 
J

Jamis Buck

Kevin said:
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.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: dates earlier than 1970?"

|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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top