function getOnCallWeekRangeWithTZ($date) { // This function is like the one above, except takes the timezone into account for accurate // retrieval of the alerts sent to the user from Splunk. Can't afford to be an hour out here. $oncall_timezone = getTeamOncallConfig('timezone'); $oncall_start_time = getTeamOncallConfig('start'); $oncall_end_time = getTeamOncallConfig('end'); $date_bits = explode('(', $date); $date = array_shift($date_bits); $ts = strtotime($date); $ts = date('l', $ts) == "Saturday" || date('l', $ts) == "Sunday" ? $ts = $ts - 172800 : $ts; date_default_timezone_set($oncall_timezone); $start = strtotime("last {$oncall_start_time}", $ts); $return_start = date('U', $start); $return_end = date('U', strtotime("next {$oncall_end_time}", $start)); date_default_timezone_set("UTC"); return array($return_start, $return_end); }
function IsWorkingHoursWithTZ($date) { // This function is like the one above, except takes the timezone into account for accurate // retrieval of the alerts sent to the user from Splunk. Can't afford to be an hour out here. $oncall_timezone = getTeamOncallConfig('timezone'); //we extract working hours from config $wanted_working_hours = getTeamOncallConfig('workinghours'); date_default_timezone_set($oncall_timezone); $return_work_hours = explode("-", $wanted_working_hours[date("l", $date)]); //we build to timestamp one with the starting working hours // the second with the en of working hours for the selected day of week of our alert $fork1 = strtotime(date("Y/m/d", $date) . " " . $return_work_hours[0]); $fork2 = strtotime(date("Y/m/d", $date) . " " . $return_work_hours[1]); //test if my date is between fork1 and fork2 and if yes, alert was fired during working hours if ($date < $fork2 and $date > $fork1) { return true; } else { return false; } }