getTransitions($time, $time); return $transition[0]['isdst']; } /** * Get the UTC offset for a specific time zone. * * @param string $timezone time-zone name * * @return string */ public static function getUTCOffset($timezone) { $offset = (strtotime('now UTC') - strtotime('now '.$timezone)); $sign = $offset >= 0 ? '+' : '-'; $offset = abs($offset); return sprintf('UTC%s%02d:%02d', $sign, $offset / 3600, ($offset / 60) % 60); } /** * Get time zone with UTC time usable as label in time-zone drop-downs. * * @param string $label time zone name or default value of time-zone dropdown * * @return string */ public static function getTimeZoneFormat($label) { $timezone = ($label === 'System' || $label === 'System default') ? 'Europe/Riga' : $label; $utc = CDateTimeHelper::getUTCOffset($timezone); return (($label === 'System' || $label === 'System default') ? $label .': ': '').'('.$utc.') '.$timezone; } /** * The days are counted from specific date and time period. * * @param string $date timestamp * @param string $period time period * * @return int */ public static function countDays($date = 'now', $period = 'P1Y') { return (new DateTime($date))->diff((new DateTime($date))->sub(new DateInterval($period)))->days; } }