in reply to Re: Timezone antidote
in thread Timezone antidote

Ewww... that sounds dangerous. Most hosted servers are actually shared boxes, and you could start screwing up other customers' timezone experiences, which, in many ways, would be worse than dealing with it yourself. Of course, if you have sole control over the entire box, go ahead :-)

Replies are listed 'Best First'.
Re^3: Timezone antidote
by Andre_br (Pilgrim) on Sep 01, 2005 at 02:17 UTC
    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

      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é

      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.