Warning: The author of this contribution does not provide support for it anymore.

Automatic Daylight Savings Time (DST)

Timezone friendly hack - Automatic Daylight Savings Time (DST)

Timezone friendly hack

by stephenju » Thu Dec 02, 2010 10:01 pm

I reported back in the old mod thread that phpBB doesn't support 'T' or 'e' in date time format correctly since it's adding a timezone offset before passing the time stamp to gmdate().

I finally broke down and came up with a hack that takes advantage of ADST mod. This hack does away with the timezone offset and calls date() instead of gmdata() to handle timezone names display correctly. It also calculates the relative day names in a more daylight saving compatible way.

The limit of this hack is it's requires PHP 5.2 or later and of course ADST mod.

It's some extra piece of code to be inserted into format_date() in includes/session.php AFTER ADST is installed:

Code: Select all

      if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO']))
      {
         return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));
      }
      /* hack starts here */
      if (defined('AUTOMATIC_DST_TIMEZONE') && (version_compare(PHP_VERSION, '5.2.0', '>'))) {
         if ($date_cache[$format]['is_short'] !== false && !$forcedate) {
            $day = false;
            $yesterday = mktime(0, 0, 0, date("m") , date("d")-1, date("Y"));
            $dayafter = mktime(0, 0, 0, date("m") , date("d")+2, date("Y"));
            if ($gmepoch >= $yesterday && $gmepoch < $dayafter) {
               $today = mktime(0, 0, 0, date("m") , date("d"), date("Y"));
               $tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
               if ($gmepoch < $today) {
                  $day = 'YESTERDAY';
               } else if ($gmepoch < $tomorrow) {
                  $day = 'TODAY';
               } else {
                  $day = 'TOMORROW';
               }
            }
            if ($day !== false) {
               return str_replace('||', $this->lang['datetime'][$day], strtr(@date($date_cache[$format]['format_short'], $gmepoch), $date_cache[$format]['lang']));
            }
         }
         return strtr(@date($date_cache[$format]['format_long'], $gmepoch), $date_cache[$format]['lang']);
      }
      /* hack ends here */
      if (!$midnight)
      {
         list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset));
         $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset;
      }


Hope this helps the 2 guys out there that are as anal as I am on time zone correctness. :)
User avatar
stephenju
Registered User
Posts: 15
Joined: Wed Mar 04, 2009 8:37 pm
Contact: