Adding time

is it possable to do this:
"$submit_time = Time.now
$rfpp = 3
$rfpp.times do
$submit_time.hour += 1
end"

I get error because you can't add time like that, so what do I do?

···

--
Posted via http://www.ruby-forum.com/.

First, you stop using global variables.

$ ri Time#+
----------------------------------------------------------------- Time#+
      time + numeric => time

···

On Apr 26, 2006, at 5:56 AM, Mohammad wrote:

is it possable to do this:
"$submit_time = Time.now
$rfpp = 3
$rfpp.times do
$submit_time.hour += 1
end"

I get error because you can't add time like that, so what do I do?

------------------------------------------------------------------------
      Addition---Adds some number of seconds (possibly fractional) to
      time and returns that value as a new time.

         t = Time.now #=> Wed Apr 09 08:56:03 CDT 2003
         t + (60 * 60 * 24) #=> Thu Apr 10 08:56:03 CDT 2003

You could also check ruby-doc.org.

So:

     t = Time.now
     t += 3 * 60

-- Daniel

one_hour = 60 * 60 # sixty seconds per minute, 60 minutes to an hour
old_submit_time = $submit_time
$submit_time = Time.at($submit_time.to_i + one_hour)

if old_submit_time.hour + 1 == $submit_time.hour
   puts "Yay!"
end

···

On Apr 25, 2006, at 11:56 PM, Mohammad wrote:

is it possable to do this:
"$submit_time = Time.now
$rfpp = 3
$rfpp.times do
$submit_time.hour += 1
end"

I get error because you can't add time like that, so what do I do?

--
Posted via http://www.ruby-forum.com/\.

Oops, forgot another * 60 in there... That's what I get for posting at 6 AM.

-- Daniel

···

On Apr 26, 2006, at 6:07 AM, Daniel Harple wrote:

t += 3 * 60

Logan Capaldo wrote:

···

On Apr 25, 2006, at 11:56 PM, Mohammad wrote:

--
Posted via http://www.ruby-forum.com/\.

one_hour = 60 * 60 # sixty seconds per minute, 60 minutes to an hour
old_submit_time = $submit_time
$submit_time = Time.at($submit_time.to_i + one_hour)

if old_submit_time.hour + 1 == $submit_time.hour
   puts "Yay!"
end

Thanks Logan and Daniel

--
Posted via http://www.ruby-forum.com/\.