Newbie question by apparent old guy;)

I was trying some code from the "Learning to Program" by Chris Pine,
excellent site by the way for learning Ruby.

The code I tried was;

puts Time.mktime(1952, 4, 3)

I get an error;

Argument Error: argument out of range

Don't tell me Ruby practices age discrimination:{o

Len Sumnler
(Old Programmer)

Works for me:

$ ruby -ve 'puts Time.mktime(1952, 4, 3)'
ruby 1.8.3 (2005-06-23) [i486-linux]
Thu Apr 03 00:00:00 CET 1952

regards,

Brian

···

On 14/08/05, len <lsumnler@gmail.com> wrote:

I was trying some code from the "Learning to Program" by Chris Pine,
excellent site by the way for learning Ruby.

The code I tried was;

puts Time.mktime(1952, 4, 3)

I get an error;

Argument Error: argument out of range

Don't tell me Ruby practices age discrimination:{o

Len Sumnler
(Old Programmer)

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

len wrote:

I was trying some code from the "Learning to Program" by Chris Pine,
excellent site by the way for learning Ruby.

The code I tried was;

puts Time.mktime(1952, 4, 3)

I get an error;

Argument Error: argument out of range

Don't tell me Ruby practices age discrimination:{o

Len Sumnler
(Old Programmer)

Interesting. Which version of Ruby are you using? It works for me at 1.8.2:

test$ irb
irb(main):001:0> puts Time.mktime(1952, 4, 3)
Thu Apr 03 00:00:00 EST 1952
=> nil

Tim Hunter
(Another Old Programmer)

Hi,

At Sun, 14 Aug 2005 23:11:13 +0900,
len wrote in [ruby-talk:152119]:

The code I tried was;

puts Time.mktime(1952, 4, 3)

I get an error;

Argument Error: argument out of range

Time class is just a wrapper of time_t. That error occurs if
time_t can't represent dates before the epoch of time_t, that
is, time_t is unsigned on your platform.

···

--
Nobu Nakada

The "Time" class stores its value as a unix timestamp, which is defined as
the number of seconds since Jan 1, 1970. Dates earlier than that won't work.

Try using "Date" or "DateTime" instead.

_Kevin

···

-----Original Message-----
From: len [mailto:lsumnler@gmail.com]
Sent: Sunday, August 14, 2005 10:11 AM
To: ruby-talk ML
Subject: Newbie question by apparent old guy;)

I was trying some code from the "Learning to Program" by Chris Pine,
excellent site by the way for learning Ruby.

The code I tried was;

puts Time.mktime(1952, 4, 3)

I get an error;

Argument Error: argument out of range

Don't tell me Ruby practices age discrimination:{o

Len Sumnler
(Old Programmer)

The "Time" class stores its value as a unix timestamp, which is defined as
the number of seconds since Jan 1, 1970. Dates earlier than that won't work.

Try using "Date" or "DateTime" instead.

What I found in some of my code:
      # Ruby 1.6 accepts only Time after 1970, Jan 1 (UTC)
      # Ruby 1.7 accepts Time before that

and if I try (debian has 1.6 and 1.8 coexisting) that is confirmed:

$ ruby1.6 -e 'p Time.local(1952)'
-e:1:in `local': argument out of range (ArgumentError)
        from -e:1
$ ruby1.8 -e 'p Time.local(1952)'
Tue Jan 01 00:00:00 CET 1952

+--- Kero ------------------------- kero@chello@nl ---+

all the meaningless and empty words I spoke |
                      Promises -- The Cranberries |

+--- M38c --- http://members.chello.nl/k.vangelder ---+

This is apparently inconsistent across platforms because if I do

'p Time.local(1952)' on my windows machine (ruby 1.8.2) I get an out of
range error.

_Kevin

···

-----Original Message-----
From: Kero [mailto:kero@chello.single-dot.nl]
Sent: Sunday, August 14, 2005 10:36 AM
To: ruby-talk ML
Subject: Re: Newbie question by apparent old guy;)

The "Time" class stores its value as a unix timestamp, which is
defined as the number of seconds since Jan 1, 1970. Dates earlier than
that won't work.

Try using "Date" or "DateTime" instead.

What I found in some of my code:
      # Ruby 1.6 accepts only Time after 1970, Jan 1 (UTC)
      # Ruby 1.7 accepts Time before that

and if I try (debian has 1.6 and 1.8 coexisting) that is confirmed:

$ ruby1.6 -e 'p Time.local(1952)'
-e:1:in `local': argument out of range (ArgumentError)
        from -e:1
$ ruby1.8 -e 'p Time.local(1952)'
Tue Jan 01 00:00:00 CET 1952

+--- Kero ------------------------- kero@chello@nl ---+

all the meaningless and empty words I spoke |
                      Promises -- The Cranberries |

+--- M38c --- http://members.chello.nl/k.vangelder ---+

I am using the latest version of Ruby 1.8.2 on a Windows XP
Professional so I will assume that it is a problem with platform.

However, now I feel really old knowing I was born before the "epoch" :slight_smile:

Len Sumnler