Exemple #1
0
function isDaylightSaving($timezoneid, $gmt_offset)
{
    /*	Get the current year by geting GMT time and date and then adding
    		offset */
    $gmt_minute = gmdate("i");
    $gmt_hour = gmdate("H");
    $gmt_month = gmdate("m");
    $gmt_day = gmdate("d");
    $gmt_year = gmdate("Y");
    $cur_year = date("Y", mktime($gmt_hour + $gmt_offset, $gmt_minute, 0, $gmt_month, $gmt_day, $gmt_year));
    switch ($timezoneid) {
        /*	North American cases: begins at 2 am on the first Sunday in April
        		and ends on the last Sunday in October.  Note: Monterrey does not
        		actually observe DST */
        case 4:
            /*	Alaska */
        /*	Alaska */
        case 5:
            /*	Pacific Time (US & Canada); Tijuana */
        /*	Pacific Time (US & Canada); Tijuana */
        case 8:
            /*	Mountain Time (US & Canada) */
        /*	Mountain Time (US & Canada) */
        case 10:
            /*	Central Time (US & Canada) */
        /*	Central Time (US & Canada) */
        case 11:
            /*	Guadalajara, Mexico City, Monterrey */
        /*	Guadalajara, Mexico City, Monterrey */
        case 14:
            /*	Eastern Time (US & Canada) */
        /*	Eastern Time (US & Canada) */
        case 16:
            /*	Atlantic Time (Canada) */
        /*	Atlantic Time (Canada) */
        case 19:
            /*	Newfoundland */
            if (afterFirstDayInMonth($cur_year, $cur_year, 4, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 7:
            /*	Chihuahua, La Paz, Mazatlan */
            if (afterFirstDayInMonth($cur_year, $cur_year, 5, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 18:
            /*	Santiago, Chile */
            if (afterSecondDayInMonth($cur_year, 10, "Sat", $gmt_offset) && beforeSecondDayInMonth($cur_year + 1, $cur_year, 3, "Sat", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 20:
            /*	Brasilia, Brazil */
            if (afterFirstDayInMonth($cur_year, $cur_year, 11, "Sun", $gmt_offset) && beforeThirdDayInMonth($cur_year, $cur_year, 2, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 23:
            /*	Mid-Atlantic */
            if (afterLastDayInMonth($cur_year, $cur_year, 3, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
            /*	EU, Russia, other cases: begins at 1 am GMT on the last Sunday
            		in March and ends on the last Sunday in October */
        /*	EU, Russia, other cases: begins at 1 am GMT on the last Sunday
        		in March and ends on the last Sunday in October */
        case 22:
            /*	Greenland */
        /*	Greenland */
        case 24:
            /*	Azores */
        /*	Azores */
        case 27:
            /*	Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London */
        /*	Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London */
        case 28:
            /*	Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna */
        /*	Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna */
        case 29:
            /*	Belgrade, Bratislava, Budapest, Ljubljana, Prague */
        /*	Belgrade, Bratislava, Budapest, Ljubljana, Prague */
        case 30:
            /*	Brussels, Copenhagen, Madrid, Paris */
        /*	Brussels, Copenhagen, Madrid, Paris */
        case 31:
            /*	Sarajevo, Skopje, Warsaw, Zagreb */
        /*	Sarajevo, Skopje, Warsaw, Zagreb */
        case 33:
            /*	Athens, Istanbul, Minsk */
        /*	Athens, Istanbul, Minsk */
        case 34:
            /*	Bucharest */
        /*	Bucharest */
        case 37:
            /*	Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius */
        /*	Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius */
        case 41:
            /*	Moscow, St. Petersburg, Volgograd */
        /*	Moscow, St. Petersburg, Volgograd */
        case 47:
            /*	Ekaterinburg */
        /*	Ekaterinburg */
        case 45:
            /*	Baku, Tbilisi, Yerevan */
        /*	Baku, Tbilisi, Yerevan */
        case 51:
            /*	Almaty, Novosibirsk */
        /*	Almaty, Novosibirsk */
        case 56:
            /*	Krasnoyarsk */
        /*	Krasnoyarsk */
        case 58:
            /*	Irkutsk, Ulaan Bataar */
        /*	Irkutsk, Ulaan Bataar */
        case 64:
            /*	Yakutsk, Sibiria */
        /*	Yakutsk, Sibiria */
        case 71:
            /*	Vladivostok */
            if (afterLastDayInMonth($cur_year, $cur_year, 3, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 35:
            /*	Cairo, Egypt */
            if (afterLastDayInMonth($cur_year, $cur_year, 4, "Fri", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 9, "Thu", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 39:
            /*	Baghdad, Iraq */
            if (afterFirstOfTheMonth($cur_year, $cur_year, 4, $gmt_offset) && beforeFirstOfTheMonth($cur_year, $cur_year, 10, $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 43:
            /*	Tehran, Iran - Note: This is an approximation to 
            			the actual DST dates since Iran goes by the Persian
            			calendar.  There are tools for converting between
            			Gregorian and Persian calendars at www.farsiweb.info.
            			This may be added at a later date for better accuracy */
            if (afterLastDayInMonth($cur_year, $cur_year, 3, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 65:
            /*	Adelaide */
        /*	Adelaide */
        case 68:
            /*	Canberra, Melbourne, Sydney */
            if (afterLastDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year + 1, 3, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 70:
            /*	Hobart */
            if (afterFirstDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year + 1, 3, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        case 73:
            /*	Auckland, Wellington */
            if (afterFirstDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset) && beforeThirdDayInMonth($cur_year, $cur_year + 1, 3, "Sun", $gmt_offset)) {
                return true;
            } else {
                return false;
            }
            break;
        default:
            break;
    }
    return false;
}
function timestamp_is_dst($timezone_id, $gmt_offset)
{
    $gmt_minute = gmdate("i");
    $gmt_hour = gmdate("H");
    $gmt_month = gmdate("m");
    $gmt_day = gmdate("d");
    $gmt_year = gmdate("Y");
    /** @noinspection PhpWrongStringConcatenationInspection */
    $cur_year = date("Y", mktime($gmt_hour + $gmt_offset, $gmt_minute, 0, $gmt_month, $gmt_day, $gmt_year));
    switch ($timezone_id) {
        case 4:
            /* Alaska */
        /* Alaska */
        case 5:
            /* Pacific Time (US & Canada); Tijuana */
        /* Pacific Time (US & Canada); Tijuana */
        case 8:
            /* Mountain Time (US & Canada) */
        /* Mountain Time (US & Canada) */
        case 10:
            /* Central Time (US & Canada) */
        /* Central Time (US & Canada) */
        case 11:
            /* Guadalajara, Mexico City, Monterrey */
        /* Guadalajara, Mexico City, Monterrey */
        case 14:
            /* Eastern Time (US & Canada) */
        /* Eastern Time (US & Canada) */
        case 16:
            /* Atlantic Time (Canada) */
        /* Atlantic Time (Canada) */
        case 19:
            /* Newfoundland */
            return afterSecondDayInMonth($cur_year, $cur_year, 3, "Sun", $gmt_offset) && beforeFirstDayInMonth($cur_year, $cur_year, 11, "Sun", $gmt_offset);
            break;
        case 7:
            /* Chihuahua, La Paz, Mazatlan */
            return afterFirstDayInMonth($cur_year, $cur_year, 5, "Sun", $gmt_offset) && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset);
            break;
        case 18:
            /* Santiago, Chile */
            return afterSecondDayInMonth($cur_year, $cur_year, 10, "Sat", $gmt_offset) && beforeSecondDayInMonth($cur_year + 1, $cur_year, 3, "Sat", $gmt_offset);
            break;
        case 20:
            /* Brasilia, Brazil */
            return afterFirstDayInMonth($cur_year, $cur_year, 11, "Sun", $gmt_offset) && beforeThirdDayInMonth($cur_year, $cur_year, 2, "Sun", $gmt_offset);
            break;
        case 23:
            /* Mid-Atlantic */
            return afterLastDayInMonth($cur_year, $cur_year, 3, "Sun") && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset);
            break;
        case 22:
            /* Greenland */
        /* Greenland */
        case 24:
            /* Azores */
        /* Azores */
        case 27:
            /* Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London */
        /* Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London */
        case 28:
            /* Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna */
        /* Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna */
        case 29:
            /* Belgrade, Bratislava, Budapest, Ljubljana, Prague */
        /* Belgrade, Bratislava, Budapest, Ljubljana, Prague */
        case 30:
            /* Brussels, Copenhagen, Madrid, Paris */
        /* Brussels, Copenhagen, Madrid, Paris */
        case 31:
            /* Sarajevo, Skopje, Warsaw, Zagreb */
        /* Sarajevo, Skopje, Warsaw, Zagreb */
        case 33:
            /* Athens, Istanbul, Minsk */
        /* Athens, Istanbul, Minsk */
        case 34:
            /* Bucharest */
        /* Bucharest */
        case 37:
            /* Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius */
        /* Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius */
        case 41:
            /* Moscow, St. Petersburg, Volgograd */
        /* Moscow, St. Petersburg, Volgograd */
        case 47:
            /* Ekaterinburg */
        /* Ekaterinburg */
        case 45:
            /* Baku, Tbilisi, Yerevan */
        /* Baku, Tbilisi, Yerevan */
        case 51:
            /* Almaty, Novosibirsk */
        /* Almaty, Novosibirsk */
        case 56:
            /* Krasnoyarsk */
        /* Krasnoyarsk */
        case 58:
            /* Irkutsk, Ulaan Bataar */
        /* Irkutsk, Ulaan Bataar */
        case 64:
            /* Yakutsk, Sibiria */
        /* Yakutsk, Sibiria */
        case 71:
            /* Vladivostok */
            return afterLastDayInMonth($cur_year, $cur_year, 3, "Sun") && beforeLastDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset);
            break;
        case 35:
            /* Cairo, Egypt */
            return afterLastDayInMonth($cur_year, $cur_year, 4, "Fri") && beforeLastDayInMonth($cur_year, $cur_year, 9, "Thu", $gmt_offset);
            break;
        case 39:
            /* Baghdad, Iraq */
            return afterFirstOfTheMonth($cur_year, $cur_year, 4, $gmt_offset) && beforeFirstOfTheMonth($cur_year, $cur_year, 10, $gmt_offset);
            break;
        case 43:
            /* Tehran, Iran */
            return afterLastDayInMonth($cur_year, $cur_year, 3, "Sun") && beforeLastDayInMonth($cur_year, $cur_year, 9, "Sun", $gmt_offset);
            break;
        case 65:
            /* Adelaide */
        /* Adelaide */
        case 68:
            /* Canberra, Melbourne, Sydney */
            return beforeFirstDayInMonth($cur_year, $cur_year, 4, "Sun", $gmt_offset) || afterFirstDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset);
            break;
        case 70:
            /* Hobart */
            return beforeFirstDayInMonth($cur_year, $cur_year, 4, "Sun", $gmt_offset) || afterFirstDayInMonth($cur_year, $cur_year, 10, "Sun", $gmt_offset);
            break;
        case 73:
            /* Auckland, Wellington */
            return beforeFirstDayInMonth($cur_year, $cur_year, 4, "Sun", $gmt_offset) || afterLastDayInMonth($cur_year, $cur_year, 9, "Sun");
            break;
        default:
            return false;
            break;
    }
}