From: Michael McDaniel Date: 2002-04-01T17:09:34+09:00 Subject: Re: Timezone name -> UTC hour offset? Sean Chittenden wrote: >> > Is there any way of going from -0800 to (PST|PDT) ? Is there a >> > module that does this? -sc >> >> The simple case of adding 8 hours to time is (assuming you wanted to >> check that time was utc, and you want to convert to PST) >> >> if time.gmt? >> t2 = time + 28800 >> end >> >> (8 hours * 60 minutes * 60 seconds = 28800) > > Thanks for the idea! It ain't pretty, but this works pretty well for > converting timezones (ex: "-0800", "-0730", etc...). ^^^^^^^^^^^^^^^^ you are welcome > > @date = @date + (("-0730".to_i.abs.divmod(100)[0] * 3600) + > ("-0730".to_i.abs.divmod(100)[1] * 60)) > > Is there any way to increment a time object without creating a new > object? Something like a +! or t.add_s!(sec) operator? -sc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Nothing that I was able to find. From the Nutshell book (or goat book, as I've seen Matz write), I paraphrase slightly... t is a Time object t + n returns a Time object with n number of seconds added. t - x If x is another Time object, returns time difference in seconds as Float object. If x is a number, returns a Time object with number of seconds subtracted. I found nothing about modifying an object in place by adding/subtracting seconds. I couldn't figure out how to convert seconds back to a Time object (e.g. t.to_f returns seconds as Float since the epoch (or t.to_i for Integer), but no way I know to convert that Float (or Integer) value back to a Time object or date string (e.g. in Tcl 'clock format [clock seconds]' returns the present date ('clock seconds' returns #seconds since the epoch)). Maybe an add_s!(sec) operator would be a useful enhancement for the future. Probably easy to add, since a time object internally is "...stored as a number of seconds since the epoch...". Then again, maybe there is a specific reason why a Time object, which corresponds to a certain time, was designed to be, in effect, immutable. (epoch == 00:00:00 January 1 1970, the (folklorish?) date of the birth of UNIX(tm)) ~mm