dates earlier than 1970?

Discussion in 'Ruby' started by Kevin Howe, Nov 3, 2004.

  1. Kevin Howe

    Kevin Howe Guest

    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?
    Kevin Howe, Nov 3, 2004
    #1
    1. Advertising

  2. Kevin Howe

    Jamis Buck Guest

    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

    http://www.jamisbuck.org/jamis
    Jamis Buck, Nov 3, 2004
    #2
    1. Advertising

  3. Hi,

    In message "Re: dates earlier than 1970?"
    on Thu, 4 Nov 2004 04:28:46 +0900, "Kevin Howe" <> 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.
    Yukihiro Matsumoto, Nov 3, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    859
    Rob Schieber
    Sep 30, 2005
  2. Stef Mientki
    Replies:
    1
    Views:
    981
    John Yeung
    Oct 8, 2009
  3. Stef Mientki
    Replies:
    2
    Views:
    342
    Tim Chase
    Oct 9, 2009
  4. Replies:
    1
    Views:
    203
    Jano Svitok
    Jul 17, 2007
  5. Tyler Cruz

    Time with Epoch earlier than 1970 question

    Tyler Cruz, Feb 8, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    121
    Gregory Toomey
    Feb 8, 2004
Loading...

Share This Page