SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    England
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PEAR::Calendar & Timezones

    I am using Pear::Calendar as the basis for an event system, my question is about dealing with timezones.

    I store all the times in the database in GMT using the http://uk.php.net/manual/en/function.gmmktime.php function. This is so that that is the server moves, the user changes their timezone etc or any other factor then we don't have to update times in the database. When a time is acutally used, it is processed by adding/subtracting hours to get into user's timezone (and DST considered as well).

    This is where my question about using PEAR:Calendar comes into play.

    At the moment, our calendar app is inconsistant, one of the reasons it is being rewritten. It uses mySQL DATE and TIME for storage but I am planning on changing this to timestamps.

    But I do not quite understand how this is going to affect putting dates into PEAR::Calendar. What is PEAR::Calendar's timezone based on? I think it is based on mktime(), which is the server time which is thus a big problem. Would a recommended solution be to change all the calls to mktime() to gmtime() and then before passing an event to the calendar, i do our normal timestamp adjustment? Then that event would appear on the calendar in the correct place, according to that user's timestamp?

    Thank you for any suggestions/help regarding this.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    England
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bumping this. Any ideas?

  3. #3
    SitePoint Enthusiast duff_beer's Avatar
    Join Date
    Jul 2003
    Location
    up in the clouds
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_man
    What is PEAR::Calendar's timezone based on? I think it is based on mktime()
    The default engine (UnixTs) is based on mktime(). There's another engine based on PEAR::Date, but you could add your own, DST-aware, it's as easy as implementing the Calendar_Engine_Interface.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    England
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way our system currently works is having all times in GMT (in software and database) and then when a user sends a time using a form we convert into GMT, and when we ever display a time we convert out of GMT. So we have tw functions to_gmt() and from_gmt() that take account of user settings, server settings etc

    I have modifed the UnixTs to use gmmktime() instead of mktime() which I think should work fine, there where only two calls to it and two calls to date() instead of gmdate which needed updating. I *think* that might be all I need to do, but not 100% sure.

    Does the way I am doing this make sense?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •