GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/common/ |
Upload File : |
<? // /common/functions_datetime.phpinc // Setup up datetime functions. #debugTrackBegin(); // currentDate() // Returns the current date. function currentDate() { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; $datetime = getdate(); $currentDate =$datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday']); if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."()=$currentDate".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return $currentDate; } // currentDateTime() // Returns the current date and time. function currentDateTime() { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; $datetime = getdate(); $currentDateTime = $datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday'])." ".twoDigit($datetime['hours']).":".twoDigit($datetime['minutes']).":".twoDigit($datetime['seconds']); if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."()=$currentDateTime".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return $currentDateTime; } // date_difference($start_date, $end_date, $workdays_only = false, $skip_holidays = false) // Calculates the number of work days between 2 given times. // $start_date = First date. // $end_date = Second date. // $workdays_only = Whether to count only work days (eg. Mon-Fri). default is false. // $skip_holidays = Whether to use the get_holidays() function to skip holiday days as well. default is false. function date_difference($start_date, $end_date, $workdays_only = false, $skip_holidays = false) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; if ($start_date == '') { return 999999999; } if ($end_date == '') { return 999999999; } $start_date = strtotime($start_date); $end_date = strtotime($end_date); if ($start_date > 0 && $end_date > 0) { $seconds_in_a_day = 86400; $sunday_val = "0"; $saturday_val = "6"; $workday_counter = 0; $holiday_array = array(); $ptr_year = intval(date("Y", $start_date)); $holiday_array[$ptr_year] = get_holidays(date("Y", $start_date)); for($day_val = $start_date; $day_val <= $end_date; $day_val+=$seconds_in_a_day) { $pointer_day = date("w", $day_val); if ($workdays_only == true) { if (($pointer_day != $sunday_val) AND ($pointer_day != $saturday_val)) { if ($skip_holidays == true) { if (intval(date("Y", $day_val))!=$ptr_year) { $ptr_year = intval(date("Y", $day_val)); $holiday_array[$ptr_year] = get_holidays(date("Y", $day_val)); } if (!in_array($day_val, $holiday_array[date("Y", $day_val)])) { $workday_counter++; } } else { $workday_counter++; } } } else { if ($skip_holidays == true) { if (intval(date("Y", $day_val))!=$ptr_year) { $ptr_year = intval(date("Y", $day_val)); $holiday_array[$ptr_year] = get_holidays(date("Y", $day_val)); } if (!in_array($day_val, $holiday_array[date("Y", $day_val)])) { $workday_counter++; } } else { $workday_counter++; } } } $date_difference = $workday_counter; } else { $date_difference = 0; } if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($start_date, $end_date, $workdays_only, $skip_holidays)=$date_difference".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return $date_difference; } // get_holidays($inc_year) // Looks through a lists of defined holidays and tells you which one is coming up next. // $inc_year The year we are looking for holidays in function get_holidays($inc_year) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; //$year = date("Y"); $year = $inc_year; $holidays[] = new Holiday("New Year's Day", get_timestamp("$year-1-1")); //$holidays[] = new Holiday("Australia Day", get_timestamp("$year-1-26")); //$holidays[] = new Holiday("Labour Day", ordinal_day(1, 'Mon', 3, $year)); //$holidays[] = new Holiday("Anzac Day", get_timestamp("$year-4-25")); //$holidays[] = new Holiday("St. Patrick's Day", get_timestamp("$year-3-17")); //$holidays[] = new Holiday("Good Friday", easter_date($year)-86400*2); $holidays[] = new Holiday("Easter", easter_date($year)); //$holidays[] = new Holiday("Easter Monday", easter_date($year)+86400); //$holidays[] = new Holiday("Foundation Day", ordinal_day(1, 'Mon', 6, $year)); //$holidays[] = new Holiday("Queen's Birthday", ordinal_day(1, 'Mon', 10, $year)); $holidays[] = new Holiday("Memorial Day", memorial_day($year)); $holidays[] = new Holiday("Mother's Day", ordinal_day(2, 'Sun', 5, $year)); $holidays[] = new Holiday("Father's Day", ordinal_day(3, 'Sun', 6, $year)); $holidays[] = new Holiday("Independence Day", get_timestamp("$year-7-4")); $holidays[] = new Holiday("Labor Day", ordinal_day(1, 'Mon', 9, $year)); $holidays[] = new Holiday("Veterans Day", get_timestamp("$year-11-11")); $holidays[] = new Holiday("Christmas", get_timestamp("$year-12-25")); //$holidays[] = new Holiday("Boxing Day", get_timestamp("$year-12-26")); /** / foreach ( $holidays as $holiday) { d_Var('$holiday->name',get_object_vars($holiday),'d'); } /**/ $numHolidays = count($holidays) - 1; $holidayDatesOnly = array(); for ($i = 0; $i < $numHolidays; $i++) { $holidayDatesOnly[] = $holidays[$i]->date; } unset($holidays); if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') { $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($inc_year)=Array"; foreach($holidayDatesOnly as $key=>$value) { $_SESSION['TRACK'] .= " [$key]=$value"; } $_SESSION['TRACK'] .= ": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; } return $holidayDatesOnly; } // get_timestamp($MySqlDateTime) // Takes a datetime in yyyy-mm-dd hh:mm:ss format and returns a PHP timestamp // $MySqlDateTime = The date to convert in yyyy-mm-dd hh:mm:ss format. // $atMidnight = 1 = a time of 00:00:00, 0 = time from MySqlDateTime (default). function get_timestamp($MySqlDateTime,$atMidnight = 0) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; /** / // Split the date from the time. $dateTime = explode(" ",$MySqlDateTime); // Split the date into year, month, day. if (isset($dateTime[0])) { $datePart = explode("-",$dateTime[0]); } else { $datePart = ''; } for ($i=0; $i<3; $i++) { if (!isset($datePart[$i]) || $datePart[$i] == '') { $datePart[$i] = 0;; } } // Split the time int hour, minute, second. if (isset($dateTime[1]) && !$atMidnight) { $timePart = explode(":",$dateTime[1]); } else { $timePart = ''; } for ($i=0; $i<3; $i++) { if (!isset($timePart[$i]) || $timePart[$i] == '') { $timePart[$i] = 0;; } } #echo "\$MySqlDateTime=",$MySqlDateTime,": ",basename(__FILE__),": ",__LINE__,"<br>\n"; #echo "\$datePart="; print_r($datePart); echo ": ",basename(__FILE__),": ",__LINE__,"<br>\n"; #echo "\$timePart="; print_r($timePart); echo ": ",basename(__FILE__),": ",__LINE__,"<br>\n"; // Create the timestamp mktime ($hour, $minute, $second, $month, $day, $year). $var_timestamp = mktime ($timePart[0],$timePart[1],$timePart[2],$datePart[1],$datePart[2],$datePart[0]); /**/ $var_timestamp = strtotime($MySqlDateTime); if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($MySqlDateTime,$atMidnight)=$var_timestamp".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return($var_timestamp); } // Holiday:class // Holds a holiday name and date. class Holiday{ //var $name; //var $date; public $name; public $date; // Contructor to define the details of each holiday as it is created. function __construct($name, $date) { $this->name = $name; // Official name of holiday. $this->date = $date; // UNIX timestamp of date. } } // memorial_day($inc_year) // Returns the date of Memorial Day for a givven year. // $inc_year = The year to calc Memorial Day for. function memorial_day($inc_year) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; for($date_stepper = intval(date("t", strtotime("$inc_year-05-01"))); $date_stepper >= 1; $date_stepper--) { if (date("l", strtotime("$inc_year-05-$date_stepper"))=="Monday") { $memorial_day = strtotime("$inc_year-05-$date_stepper"); if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($inc_year)=$memorial_day".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return $memorial_day; break; } } } // ordinal_day($ord, $day, $month, $year) // Returns the date of the $ord $day of the $month. // I.E. ordinal_day(3, 'Sun', 5, 2001) returns the date of the 3rd Sunday of May (ie. Mother's Day). // $ord = The week count. // $day = The day of the week. Must be 3 char abbrev Mon, Tue, Wed, Thu, Fri, Sat, Sun. // $month = The month of the yeat. // $year = The year. /* @return unknown */ function ordinal_day($ord, $day, $month, $year) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; $firstOfMonth = get_timestamp("$year-$month-01"); $lastOfMonth = $firstOfMonth + date("t", $firstOfMonth) * 86400; $dayOccurs = 0; for ($i = $firstOfMonth; $i < $lastOfMonth ; $i += 86400) { if (date("D", $i) == $day) { $dayOccurs++; if ($dayOccurs == $ord) { $ordDay = $i; } } } if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($ord, $day, $month, $year)=$ordDay".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; return $ordDay; } // time_difference($start, $end) /** * Function to calculate date or time difference. * * Function to calculate date or time difference. Returns an array or * false on error. * * @author J de Silva <giddomains@gmail.com> * @copyright Copyright © 2005, J de Silva * @link http://www.gidnetwork.com/b-16.html Get the date / time difference with PHP * @param string $start * @param string $end * @return array */ function time_difference($start, $end) { $debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK; $uts['start'] = strtotime($start); $uts['end'] = strtotime($end); if ($uts['start']!==-1 && $uts['end']!==-1) { if ($uts['end'] >= $uts['start']) { $diff = $uts['end'] - $uts['start']; if ($days=intval((floor($diff/86400)))) $diff = $diff % 86400; if ($hours=intval((floor($diff/3600)))) $diff = $diff % 3600; if ($minutes=intval((floor($diff/60)))) $diff = $diff % 60; $diff = intval($diff); $time_difference = array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff); } else { trigger_error("Ending date/time is earlier than the start date/time", E_USER_WARNING); $time_difference = false; } } else { trigger_error("Invalid date/time data detected", E_USER_WARNING); $time_difference = false; } if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') { $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($start, $end)=Array"; foreach($time_difference as $key=>$value) { $_SESSION['TRACK'] .= " [$key]=$value"; } $_SESSION['TRACK'] .= ": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; } return $time_difference; } function valid_date($date, $format='') { #if (da()) printVar('$date',$date); $dateParts = explode(' ',$date); $date = $dateParts[0]; // Throw away time. #if (da()) printVar('$date',$date); if ( substr_count($date,'-') == 2 || substr_count($date,'/') == 2 || substr_count($date,'.') == 2 ) { if (substr_count($date,'/') == 2 ) $date = str_replace("/","-",$date); if (substr_count($date,'.') == 2 ) $date = str_replace(".","-",$date); $dateArray = explode("-", $date); if ( strlen($dateArray[0]) == 4 ) { // yyyy-mm-dd format. $Year = $dateArray[0]; $Month = $dateArray[1]; $Day = $dateArray[2]; } else { // mm/dd/yyyy format. $Year = $dateArray[2]; $Month = $dateArray[0]; $Day = $dateArray[1]; } #if (da()) printVar('$Month',$Month); #if (da()) printVar('$Day',$Day); #if (da()) printVar('$Year',$Year); #if (da()) printVar('is_numeric($Year)',is_numeric($Year)); if ( !is_numeric($Month) || !is_numeric($Day) || !is_numeric($Year) ) { $valid_date = false; } else { $valid_date = checkdate($Month, $Day, $Year); } } else { $valid_date = false; } if ( $valid_date ) { switch ($format) { case 'USA': $valid_date = twoDigit($Month)."/".twoDigit($Day)."/".$Year; break; default: $valid_date = $Year."-".twoDigit($Month)."-".twoDigit($Day); break; } } return $valid_date; } function valid_time($time, $format="", $valid_time_DEBUG=false) { #$valid_time_DEBUG = true; if ( isset($time) && $time != '' ) { if ($valid_time_DEBUG) printVar('$time',$time); $valid_time = true; $time = explode(':',str_replace("a",":a",str_replace("p",":p",str_replace("m","",str_replace(" ","",strtolower($time)))))); if ($valid_time_DEBUG) printVar('count($time)',count($time)); if ($valid_time_DEBUG) printVar('$time',$time); // Fix $time to hh:mm:ss:meridiem. if ( count($time) == 3 && ( $time[2] == 'a' || $time[2] == 'p' ) ) { // hh:mm:meridiem. $time[3] = $time[2]; // Move meridiem. $time[2] = 0; // Set ss. if ($valid_time_DEBUG) printVar('$time',$time); } if ( count($time) == 2 ) { if ( $time[1] == 'a' || $time[1] == 'p' ) { // hh:meridiem. $time[3] = $time[1]; // Move meridiem. $time[1] = 0; // Set mm. $time[2] = 0; // Set ss. if ($valid_time_DEBUG) printVar('$time',$time); } else { // hh:mm. $time[2] = 0; // Set seconds. if ($valid_time_DEBUG) printVar('$time',$time); } } if ( count($time) == 1 ) { // hh. $time[1] = 0; // Set mm. $time[2] = 0; // Set ss. if ($valid_time_DEBUG) printVar('$time',$time); } if ( !isset($time[3]) ) { // No meridiem. if ( $time[0] < 12 || $time[0] == 24 ) { $time[3] = 'a'; if ($valid_time_DEBUG) printVar('$time',$time); } else { $time[3] = 'p'; if ($valid_time_DEBUG) printVar('$time',$time); } } if ( is_numeric($time[0]) && $time[0] == ((int)$time[0]) && $time[0] >= 0 && $time[0] <= 24 && is_numeric($time[1]) && $time[1] == ((int)$time[1]) && $time[1] >= 0 && $time[1] <= 59 && is_numeric($time[2]) && $time[2] == ((int)$time[2]) && $time[2] >= 0 && $time[2] <= 59 && ( $time[3] == 'a' || $time[3] == 'p' ) ) { // hh mm, and ss are integers in range and meridiem is a or p. if ( $time[0] > 12 ) { if ( $time[0] != 24 ) { $time[0] -= 12; // Subtract 12 if 24 hr time. if ($valid_time_DEBUG) printVar('$time',$time); } else { if ( $time[1] == 0 ) { $time[0] = 0; // turn 24:00 into 00:00. $time[3] = "a"; if ($valid_time_DEBUG) printVar('$time',$time); } else { // use of 24 hh with non 0 mm. $valid_time = false; } } } if ( strlen($format) == 3 && substr($format,strlen($format)-1,1) == 's') { $seconds = ':'.twoDigit($time[2]); $format = substr($format,0,strlen($format)-1); } else { $seconds = ''; } #if ( $format != '' ) printVar('$format',$format); switch ($format) { case '24': if ( $time[3] == 'p' && $time[0] != 12 ) { $time[0] += 12; if ($valid_time_DEBUG) printVar('$time',$time); } else { #if ( $time[0] == 12 ) { # $time[0] -= 12; # if ($valid_time_DEBUG) printVar('$time',$time); #} } if ( $time[0] == 24 && $time[3] == 'p' ) { $time[0] -= 12; if ($valid_time_DEBUG) printVar('$time',$time); } $valid_time = twoDigit($time[0]).":".twoDigit($time[1]).$seconds; break; default: if ( $time[0] == 0 ) { $time[0] += 12; if ($valid_time_DEBUG) printVar('$time',$time); } if ( strlen($time[0]) == 2 && substr($time[0],0,1) == '0' ) { $time[0] = substr($time[0],1,1); if ($valid_time_DEBUG) printVar('$time',$time); } if ( $time[3] == 'a' ) { $meridiem = ' am'; } else { $meridiem = ' pm'; } $valid_time = $time[0].":".twoDigit($time[1]).$seconds.$meridiem; break; } } else { // hh or mm is not valid. $valid_time = false; } } else { // time is not set or blank. $valid_time = false; } if ($valid_time_DEBUG) printVar('$time',$time); if ($valid_time_DEBUG) printVar('$valid_time',$valid_time); #if ($valid_time_DEBUG) exit; return $valid_time; } #debugTrackEnd(); ?>