public static function getDateOfNextDayOfMonth($anchor_epoch, $day_of_month_epoch, $day_of_month = NULL)
 {
     //Anchor Epoch is the anchor date to start searching from.
     //Day of month epoch is the epoch we use to extract the day of the month from.
     Debug::text('-------- ', __FILE__, __LINE__, __METHOD__, 10);
     Debug::text('Anchor Epoch: ' . TTDate::getDate('DATE+TIME', $anchor_epoch) . ' Day Of Month Epoch: ' . TTDate::getDate('DATE+TIME', $day_of_month_epoch) . ' Day Of Month: ' . $day_of_month, __FILE__, __LINE__, __METHOD__, 10);
     if ($anchor_epoch == '') {
         return FALSE;
     }
     if ($day_of_month_epoch == '' and $day_of_month == '') {
         return FALSE;
     }
     if ($day_of_month_epoch == '' and $day_of_month != '' and $day_of_month <= 31) {
         $tmp_days_in_month = TTDate::getDaysInMonth($anchor_epoch);
         if ($day_of_month > $tmp_days_in_month) {
             $day_of_month = $tmp_days_in_month;
         }
         unset($tmp_days_in_month);
         $day_of_month_epoch = mktime(date('H', $anchor_epoch), date('i', $anchor_epoch), date('s', $anchor_epoch), date('m', $anchor_epoch), $day_of_month, date('Y', $anchor_epoch));
     }
     //If the anchor date is AFTER the day of the month, we want to get the same day
     //in the NEXT month.
     $src_dom = date('j', $anchor_epoch);
     $dst_dom = date('j', $day_of_month_epoch);
     //Debug::text('Anchor DOM: '. $src_dom .' DST DOM: '. $dst_dom, __FILE__, __LINE__, __METHOD__,10);
     if ($src_dom > $dst_dom) {
         //Debug::text('Anchor DOM is greater then Dest DOM', __FILE__, __LINE__, __METHOD__,10);
         //Get the epoch of the first day of the next month
         //Use getMiddleDayEpoch so daylight savings doesn't throw us off.
         $anchor_epoch = TTDate::getMiddleDayEpoch(TTDate::getEndMonthEpoch($anchor_epoch) + 1);
         //Find out how many days are in this month
         $days_in_month = TTDate::getDaysInMonth($anchor_epoch);
         if ($dst_dom > $days_in_month) {
             $dst_dom = $days_in_month;
         }
         $retval = $anchor_epoch + ($dst_dom - 1) * 86400;
     } else {
         //Debug::text('Anchor DOM is equal or LESS then Dest DOM', __FILE__, __LINE__, __METHOD__,10);
         $retval = mktime(date('H', $anchor_epoch), date('i', $anchor_epoch), date('s', $anchor_epoch), date('m', $anchor_epoch), date('j', $day_of_month_epoch), date('Y', $anchor_epoch));
     }
     return TTDate::getBeginDayEpoch($retval);
 }
 function inApplyFrequencyWindow($current_epoch, $offset, $pay_period_end_date = NULL, $hire_date = NULL)
 {
     Debug::Text('Offset: ' . $offset, __FILE__, __LINE__, __METHOD__, 10);
     $retval = FALSE;
     switch ($this->getApplyFrequency()) {
         case 10:
             //Pay Period
             if ($pay_period_end_date == '') {
                 return FALSE;
             }
             if ($pay_period_end_date >= $current_epoch - $offset and $pay_period_end_date <= $current_epoch) {
                 $retval = TRUE;
             }
             break;
         case 20:
             //Year
             if ($this->getApplyFrequencyHireDate() == TRUE) {
                 Debug::Text('Hire Date: ' . TTDate::getDate('DATE', $hire_date), __FILE__, __LINE__, __METHOD__, 10);
                 $year_epoch = mktime(0, 0, 0, TTDate::getMonth($hire_date), TTDate::getDayOfMonth($hire_date), TTDate::getYear($current_epoch));
             } else {
                 Debug::Text('Static Date', __FILE__, __LINE__, __METHOD__, 10);
                 $year_epoch = mktime(0, 0, 0, $this->getApplyFrequencyMonth(), $this->getApplyFrequencyDayOfMonth(), TTDate::getYear($current_epoch));
             }
             Debug::Text('Year EPOCH: ' . TTDate::getDate('DATE+TIME', $year_epoch), __FILE__, __LINE__, __METHOD__, 10);
             if ($year_epoch >= $current_epoch - $offset and $year_epoch <= $current_epoch) {
                 $retval = TRUE;
             }
             break;
         case 30:
             //Month
             $apply_frequency_day_of_month = $this->getApplyFrequencyDayOfMonth();
             //Make sure if they specify the day of month to be 31, that is still works for months with 30, or 28-29 days, assuming 31 basically means the last day of the month
             if ($apply_frequency_day_of_month > TTDate::getDaysInMonth($current_epoch)) {
                 $apply_frequency_day_of_month = TTDate::getDaysInMonth($current_epoch);
                 Debug::Text('Apply frequency day of month exceeds days in this month, using last day of the month instead: ' . $apply_frequency_day_of_month, __FILE__, __LINE__, __METHOD__, 10);
             }
             $month_epoch = mktime(0, 0, 0, TTDate::getMonth($current_epoch), $apply_frequency_day_of_month, TTDate::getYear($current_epoch));
             Debug::Text('Day of Month: ' . $this->getApplyFrequencyDayOfMonth() . ' Month EPOCH: ' . TTDate::getDate('DATE+TIME', $month_epoch) . ' Current Month: ' . TTDate::getMonth($current_epoch), __FILE__, __LINE__, __METHOD__, 10);
             Debug::Text('Month EPOCH: ' . TTDate::getDate('DATE+TIME', $month_epoch) . '(' . $month_epoch . ') Greater Than: ' . TTDate::getDate('DATE+TIME', $current_epoch - $offset) . ' Less Than: ' . TTDate::getDate('DATE+TIME', $current_epoch) . '(' . $current_epoch . ')', __FILE__, __LINE__, __METHOD__, 10);
             if ($month_epoch >= $current_epoch - $offset and $month_epoch <= $current_epoch) {
                 $retval = TRUE;
             }
             break;
         case 40:
             //Week
             Debug::Text('Current Day Of Week: ' . TTDate::getDayOfWeek($current_epoch - $offset), __FILE__, __LINE__, __METHOD__, 10);
             if ($this->getApplyFrequencyDayOfWeek() == TTDate::getDayOfWeek($current_epoch - $offset)) {
                 $retval = TRUE;
             }
             break;
     }
     Debug::Text('RetVal: ' . (int) $retval, __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
Exemple #3
0
 static function inApplyFrequencyWindow($frequency_id, $start_date, $end_date, $frequency_criteria = array())
 {
     /*
     		 Frequency IDs:
     												20 => 'Annually',
     												25 => 'Quarterly',
     												30 => 'Monthly',
     												40 => 'Weekly',
     												100 => 'Specific Date', //Pay Period Dates, Hire Dates, Termination Dates, etc...
     */
     if (!isset($frequency_criteria['month'])) {
         $frequency_criteria['month'] = 0;
     }
     if (!isset($frequency_criteria['day_of_month'])) {
         $frequency_criteria['day_of_month'] = 0;
     }
     if (!isset($frequency_criteria['day_of_week'])) {
         $frequency_criteria['day_of_week'] = 0;
     }
     if (!isset($frequency_criteria['quarter_month'])) {
         $frequency_criteria['quarter_month'] = 0;
     }
     if (!isset($frequency_criteria['date'])) {
         $frequency_criteria['date'] = 0;
     }
     //Debug::Arr($frequency_criteria, 'Freq ID: '. $frequency_id .' Date: Start: '. TTDate::getDate('DATE+TIME', $start_date) .'('.$start_date.') End: '. TTDate::getDate('DATE+TIME', $end_date) .'('.$end_date.')', __FILE__, __LINE__, __METHOD__,10);
     $retval = FALSE;
     switch ($frequency_id) {
         case 20:
             //Annually
             $year_epoch1 = mktime(TTDate::getHour($start_date), TTDate::getMinute($start_date), TTDate::getSecond($start_date), $frequency_criteria['month'], $frequency_criteria['day_of_month'], TTDate::getYear($start_date));
             $year_epoch2 = mktime(TTDate::getHour($end_date), TTDate::getMinute($end_date), TTDate::getSecond($end_date), $frequency_criteria['month'], $frequency_criteria['day_of_month'], TTDate::getYear($end_date));
             //Debug::Text('Year1 EPOCH: '. TTDate::getDate('DATE+TIME', $year_epoch1) .'('. $year_epoch1 .')', __FILE__, __LINE__, __METHOD__,10);
             //Debug::Text('Year2 EPOCH: '. TTDate::getDate('DATE+TIME', $year_epoch2) .'('. $year_epoch2 .')', __FILE__, __LINE__, __METHOD__,10);
             if ($year_epoch1 >= $start_date and $year_epoch1 <= $end_date or $year_epoch2 >= $start_date and $year_epoch2 <= $end_date) {
                 $retval = TRUE;
             }
             break;
         case 25:
             //Quarterly
             //Handle quarterly like month, we just need to set the specific month from quarter_month.
             if (abs($end_date - $start_date) > 86400 * 93) {
                 //3 months
                 $retval = TRUE;
             } else {
                 for ($i = TTDate::getMiddleDayEpoch($start_date); $i <= TTDate::getMiddleDayEpoch($end_date); $i += 86400 * 1) {
                     if (self::getYearQuarterMonthNumber($i) == $frequency_criteria['quarter_month'] and $frequency_criteria['day_of_month'] == self::getDayOfMonth($i)) {
                         $retval = TRUE;
                         break;
                     }
                 }
             }
             break;
         case 30:
             //Monthly
             //Make sure if they specify the day of month to be 31, that is still works for months with 30, or 28-29 days, assuming 31 basically means the last day of the month
             if ($frequency_criteria['day_of_month'] > TTDate::getDaysInMonth($start_date) or $frequency_criteria['day_of_month'] > TTDate::getDaysInMonth($end_date)) {
                 $frequency_criteria['day_of_month'] = TTDate::getDaysInMonth($start_date);
                 if (TTDate::getDaysInMonth($end_date) < $frequency_criteria['day_of_month']) {
                     $frequency_criteria['day_of_month'] = TTDate::getDaysInMonth($end_date);
                 }
                 //Debug::Text('Apply frequency day of month exceeds days in this month, using last day of the month instead: '. $frequency_criteria['day_of_month'], __FILE__, __LINE__, __METHOD__,10);
             }
             $month_epoch1 = mktime(TTDate::getHour($start_date), TTDate::getMinute($start_date), TTDate::getSecond($start_date), TTDate::getMonth($start_date), $frequency_criteria['day_of_month'], TTDate::getYear($start_date));
             $month_epoch2 = mktime(TTDate::getHour($end_date), TTDate::getMinute($end_date), TTDate::getSecond($end_date), TTDate::getMonth($end_date), $frequency_criteria['day_of_month'], TTDate::getYear($end_date));
             //Debug::Text('Day of Month: '. $frequency_criteria['day_of_month'] .' Month EPOCH: '. TTDate::getDate('DATE+TIME', $month_epoch1) .' Current Month: '. TTDate::getMonth( $start_date ), __FILE__, __LINE__, __METHOD__,10);
             //Debug::Text('Month1 EPOCH: '. TTDate::getDate('DATE+TIME', $month_epoch1) .'('. $month_epoch1 .') Greater Than: '. TTDate::getDate('DATE+TIME', ($start_date)) .' Less Than: '.  TTDate::getDate('DATE+TIME', $end_date) .'('. $end_date .')', __FILE__, __LINE__, __METHOD__,10);
             //Debug::Text('Month2 EPOCH: '. TTDate::getDate('DATE+TIME', $month_epoch2) .'('. $month_epoch2 .') Greater Than: '. TTDate::getDate('DATE+TIME', ($start_date)) .' Less Than: '.  TTDate::getDate('DATE+TIME', $end_date) .'('. $end_date .')', __FILE__, __LINE__, __METHOD__,10);
             if ($month_epoch1 >= $start_date and $month_epoch1 <= $end_date or $month_epoch2 >= $start_date and $month_epoch2 <= $end_date) {
                 $retval = TRUE;
             }
             break;
         case 40:
             //Weekly
             $start_dow = self::getDayOfWeek($start_date);
             $end_dow = self::getDayOfWeek($end_date);
             if ($start_dow == $frequency_criteria['day_of_week'] or $end_dow == $frequency_criteria['day_of_week']) {
                 $retval = TRUE;
             } else {
                 if ($end_date - $start_date > 86400 * 7) {
                     $retval = TRUE;
                 } else {
                     for ($i = TTDate::getMiddleDayEpoch($start_date); $i <= TTDate::getMiddleDayEpoch($end_date); $i += 86400) {
                         if (self::getDayOfWeek($i) == $frequency_criteria['day_of_week']) {
                             $retval = TRUE;
                             break;
                         }
                     }
                 }
             }
             break;
         case 100:
             //Specific date
             Debug::Text('Specific Date: ' . TTDate::getDate('DATE+TIME', $frequency_criteria['date']), __FILE__, __LINE__, __METHOD__, 10);
             if ($frequency_criteria['date'] >= $start_date and $frequency_criteria['date'] <= $end_date) {
                 $retval = TRUE;
             }
             break;
     }
     Debug::Text('Retval ' . (int) $retval, __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }