[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Q on Mac Time Zones



On Fri, 8 Jan 1999 07:42:50 -0500, Chris Nandor wrote:

>Untested in other places, but should work anywhere, I think:
>
>  #!perl
>  use Time::Local;
>  $diff = (timelocal(localtime) - timelocal(gmtime)) / 36;
[snipped the ugly, remedied regex part ]

What's that " / 36 "? 3600 seconds in an hour... Oh, I see. You divide
the time difference in seconds so you get 100 times the time difference
in hours.

Well, that won't work everywhere. There ARE time zones in the world,
where the time difference is NOT an integer multiple of an hour. That's
what the 3rd and 4th digit are for, anyway. I forgot the exact details,
but I do remember that the western part of Australia and the middle part
have a time difference of a *half* hour.

Let's for the record suppose that one of these time zones differs 8.5
hours with GMT. Your result would be "+0850". But I suppose it should
really be "+0830", i.e. hours + minutes. Now, remedy that.

   use Time::Local;
  $diff = (timelocal(localtime) - timelocal(gmtime)) / 3600; # hours
   # test
   	$diff = 8.5; 
   $timezone = sprintf "%+0.2d%0.2d", $diff,
	60*(abs($diff)-int(abs($diff)));
   print $timezone;
__END__
+8030

There.

	Bart.

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch