in reply to Re^2: Timezone antidote
in thread Timezone antidote

Hello fellows,

Sadly iīm in a shared hosting plan and canīt tell Mr Server to adjust his watch. And about the all-GMT solution, Iīm agraid it wonīt fit also, because one of the needs is to print out valid time for events the customers here in Brazil will see the logs, you know? Like, they canīt shop and them see messages and emails saying theyīve bought 4 hours ago in the next second.

Maybe I have to adjust the time by hand, adding 4 * 3600 seconds to my Perlīs $now variable every time I record a datetime. But I thought there were modules to act as a layer everytime I called localtime() and adjust the timezone, arenīt there?

UPDATE: As for mysql, how about the .my.cnf file. I donīt have one in my root, but canīt be a way to set up the user-specific timezone, like in this articleīs 4th user-contributed note? http://www.modwest.com/help/kb6-256.html

Replies are listed 'Best First'.
Re^4: Timezone antidote
by hatter (Pilgrim) on Sep 01, 2005 at 12:00 UTC
    GMT is the storage solution, not the output format. Store all the times in UTC/GMT, and when you actually need to print them out, then use TZ-aware tools and use the localtime features. From one of my scripts, I have:
    use POSIX qw(LC_TIME); $ENV{'TZ'} = "GMT-1"; $locale = "gb_UK"; POSIX::setlocale(LC_TIME,$locale); my $todaysdate = POSIX::strftime("%a %b %d %H:%M",localtime());
    For the machines in the UK, that changes between -1 and -0 for summer and not, and the machines in germany, that changes between -2 and -1 for summer and winter, and locale is de_DE. Calling localtime() will then view the time as it should be in your locale.


    the hatter
      Hello hatter and everybody

      Thanks for the tips. Specially yours, hatter. But, tell me, any tip for mysql? My problem is the 'timestamp' fields, on wich rely my code and Iīd have to convert them all to 'datetime' and make my code treat this offset.

      I tried setting the default of this 'timestamp' column to CURRENT_TIMESTAMP + interval 4 hour but this formula isnīt accepted by mysql as a default. I thought then about setting some kind of variable as now() + interval 4 hour but I think it wonīt work either.

      Any ideas? My host said thereīs no way to set a different time_zone through .my.cnf

      Thanks

      André

        DATE_ADD(NOW(),INTERVAL 4 hour) would be the option if you're setting itn in your INSERTs, DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 4 hour) may work in the column definition as the default value, if you've not tried that already.


        the hatter
Re^4: Timezone antidote
by Tanktalus (Canon) on Sep 01, 2005 at 03:14 UTC

    Side note - if it's just emails you're worried about, you can start by just sending the emails with any timezone - the header should automatically be adjusted by the client. For times inside the email, check out Time::Zone - rather than adding 4*3600, try tz_offset('...') where '...' is the timezone you want your output to be in.

    Perhaps one of the more experienced pmdevils here would know how PM handles the same situation since everyone can specify the timezone they want to see stuff in.