Bonfire icon indicating copy to clipboard operation
Bonfire copied to clipboard

Timezone with DST (Daylight Saving Time)

Open xcript opened this issue 11 years ago • 2 comments

As described here: http://forums.cibonfire.com/discussion/1020/timezone-with-dst-daylight-saving-time#Item_2

CI doesn't care about timezones with DST. And Bonfire does it equal. It is not possible to get the correct time for the timezone "Europe/Berlin" / "CET". Currently most countries in Europe as Germany have summertime, which means the time offset to UTC ist currently +2. Bonfire saves the value "UP1" for +1 in the user table, but this is not the time of the user! So this is wrong and a great bug! Please correct this and save the normally used string like "Europe/Berlin" in the user table. Otherwise it will not be possible to get the correct time offset!

The solution:

Info: You have to change the form_validation in the controller-files "users.php" and "settings.php", so that they excepts more than 4 characters in the timezone field. You have to change the length value of the database field "timezone" in the table "users" too. Just set it to 50 for example.

if ( ! function_exists('timezone_menu'))
    {
    function timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
    {
        $CI =& get_instance();
        $CI->lang->load('date');

        if ($default == 'GMT')
        {
            $default = 'UTC';
        }

        $menu = '<select name="'.$name.'"';

        if ($class != '')
        {
            $menu .= ' class="'.$class.'"';
        }

        $menu .= ">\n";

        // get list of available timezones (PHP >= 5.2.0!!!)
        $timezone_identifiers = DateTimeZone::listIdentifiers();

        $continent = "";

        foreach($timezone_identifiers as $value)
        {
            if (preg_match( '/^(Africa|America|Antartica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)\//', $value))
            {
                $ex = explode("/", $value); //obtain continent, city

                if ($continent != $ex[0])
                {
                    if ($continent != "")
                    {
                        $menu .= '</optgroup>';
                    }

                    $menu .= '<optgroup label="'. $ex[0].'">';
                }

                $city = $ex[1];
                $continent = $ex[0];

                $selected = ($default == $value) ? ' selected="selected"' : '';

                $menu .= '<option value="'.$value.'"'. $selected. '>'.$city.'</option>';
            }
        }

        $menu .= "</select>";

        return $menu;

    }
} // end timezone_menu

xcript avatar Jul 16 '13 15:07 xcript

Since the bulk of this involves a change to CI's handling of time zones, it would probably be best to submit the timezone_menu issue to CodeIgniter (https://github.com/EllisLab/CodeIgniter/).

It may be worth considering a more standard method of dealing with time zones on our end, though. I've gotten to the point of removing the date helper from my older modules because it usually makes things more difficult in the long run, even if it seems easier when you initially start using CI/Bonfire.

mwhitneysdsu avatar Jul 19 '13 16:07 mwhitneysdsu

Does the fix for #494 help at all?

mwhitneysdsu avatar Oct 30 '13 21:10 mwhitneysdsu