示例#1
0
 function test_getNearestWeekDay()
 {
     //case 0: //No adjustment
     //	break 2;
     //case 1: //Previous day
     //	$epoch -= 86400;
     //	break;
     //case 2: //Next day
     //	$epoch += 86400;
     //	break;
     //case 3: //Closest day
     $date1 = strtotime('16-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 0), strtotime('16-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 1), strtotime('15-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 2), strtotime('18-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 3), strtotime('15-Jan-2010 12:00PM'));
     $date2 = strtotime('17-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date2, 3), strtotime('18-Jan-2010 12:00PM'));
     $holidays = array(TTDate::getBeginDayEpoch(strtotime('15-Jan-2010')));
     $date1 = strtotime('16-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 3, $holidays), strtotime('14-Jan-2010 12:00PM'));
     $holidays = array(TTDate::getBeginDayEpoch(strtotime('15-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('14-Jan-2010')));
     $date1 = strtotime('16-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 1, $holidays), strtotime('13-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 3, $holidays), strtotime('18-Jan-2010 12:00PM'));
     $holidays = array(TTDate::getBeginDayEpoch(strtotime('15-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('14-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('18-Jan-2010')));
     $date1 = strtotime('16-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 1, $holidays), strtotime('13-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 3, $holidays), strtotime('13-Jan-2010 12:00PM'));
     $holidays = array(TTDate::getBeginDayEpoch(strtotime('15-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('14-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('13-Jan-2010')), TTDate::getBeginDayEpoch(strtotime('18-Jan-2010')));
     $date1 = strtotime('16-Jan-2010 12:00PM');
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 1, $holidays), strtotime('12-Jan-2010 12:00PM'));
     $this->assertEquals(TTDate::getNearestWeekDay($date1, 3, $holidays), strtotime('19-Jan-2010 12:00PM'));
 }
 function getTransactionBusinessDay($epoch)
 {
     Debug::Text('Epoch: ' . TTDate::getDate('DATE+TIME', $epoch), __FILE__, __LINE__, __METHOD__, 10);
     $holiday_epochs = array();
     $user_ids = $this->getUser();
     if (count($user_ids) > 0) {
         $hlf = TTnew('HolidayListFactory');
         $hlf->getByPolicyGroupUserIdAndStartDateAndEndDate($user_ids, $epoch - 86400 * 14, $epoch + 86400 * 2);
         if ($hlf->getRecordCount() > 0) {
             foreach ($hlf as $h_obj) {
                 Debug::Text('Found Holiday Epoch: ' . TTDate::getDate('DATE+TIME', $h_obj->getDateStamp()) . ' Name: ' . $h_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
                 $holiday_epochs[] = $h_obj->getDateStamp();
             }
             //Debug::Arr($holiday_epochs, 'Holiday Epochs: ', __FILE__, __LINE__, __METHOD__, 10);
         }
         $epoch = TTDate::getNearestWeekDay($epoch, $this->getTransactionDateBusinessDay(), $holiday_epochs);
     }
     return $epoch;
 }
 function getNextDate($epoch = FALSE)
 {
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     if ($this->getSpecialDay() == 1 or $this->getSpecialDay() == 5) {
         Debug::text('Easter Sunday Date...', __FILE__, __LINE__, __METHOD__, 10);
         //Use easter_days() instead, as easter_date returns incorrect values for some timezones/years (2010 and US/Eastern on Windows)
         //$easter_epoch = easter_date(date('Y', $epoch));
         $easter_epoch = mktime(12, 0, 0, 3, 21 + easter_days(date('Y', $epoch)), date('Y', $epoch));
         //Fix "cross-year" bug.
         if ($easter_epoch < $epoch) {
             //$easter_epoch = easter_date(date('Y', $epoch)+1);
             $easter_epoch = mktime(12, 0, 0, 3, 21 + easter_days(date('Y', $epoch) + 1), date('Y', $epoch) + 1);
         }
         if ($this->getSpecialDay() == 1) {
             Debug::text('Good Friday Date...', __FILE__, __LINE__, __METHOD__, 10);
             //$holiday_epoch = mktime(12,0,0,date('n',$easter_epoch),date('j',$easter_epoch) - 2, date('Y', $easter_epoch));
             $holiday_epoch = $easter_epoch - 2 * 86400;
         } else {
             $holiday_epoch = $easter_epoch;
         }
     } else {
         if ($this->getType() == 10) {
             //Static
             Debug::text('Static Date...', __FILE__, __LINE__, __METHOD__, 10);
             //Static date
             $holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch));
             if ($holiday_epoch < $epoch) {
                 $holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch) + 1);
             }
         } elseif ($this->getType() == 20) {
             //Dynamic - Week Interval
             Debug::text('Dynamic - Week Interval... Current Month: ' . TTDate::getMonth($epoch) . ' Holiday Month: ' . $this->getMonth(), __FILE__, __LINE__, __METHOD__, 10);
             //Dynamic
             $start_month_epoch = TTDate::getBeginMonthEpoch($epoch);
             $end_month_epoch = mktime(12, 0, 0, $this->getMonth() + 1, 1, date('Y', $epoch) + 1);
             Debug::text('Start Epoch: ' . TTDate::getDate('DATE+TIME', $start_month_epoch) . ' End Epoch: ' . TTDate::getDate('DATE+TIME', $end_month_epoch), __FILE__, __LINE__, __METHOD__, 10);
             //Get all day of weeks in the month. Determine which is less or greater then day.
             $day_of_week_dates = array();
             $week_interval = 0;
             for ($i = $start_month_epoch; $i <= $end_month_epoch; $i += 86400) {
                 if (TTDate::getMonth($i) == $this->getMonth()) {
                     $day_of_week = TTDate::getDayOfWeek($i);
                     //Debug::text('I: '. $i .'('.TTDate::getDate('DATE+TIME', $i).') Current Day Of Week: '. $day_of_week .' Looking for Day Of Week: '. $this->getDayOfWeek(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($day_of_week == abs($this->getDayOfWeek())) {
                         $day_of_week_dates[] = date('j', $i);
                         Debug::text('I: ' . $i . ' Day Of Month: ' . date('j', $i), __FILE__, __LINE__, __METHOD__, 10);
                         $week_interval++;
                     }
                     if ($week_interval >= $this->getWeekInterval()) {
                         $tmp_holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $day_of_week_dates[$this->getWeekInterval() - 1], date('Y', $i));
                         //Make sure we keep processing until the holiday comes AFTER todays date.
                         if ($tmp_holiday_epoch > $epoch) {
                             break;
                         }
                     }
                 }
             }
             //Debug::Arr($day_of_week_dates, 'Week Dates Arr: ', __FILE__, __LINE__, __METHOD__, 10);
             //$holiday_epoch = mktime(12,0,0, $this->getMonth(), $day_of_week_dates[$this->getWeekInterval()-1], date('Y', $i));
             $holiday_epoch = $tmp_holiday_epoch;
         } elseif ($this->getType() == 30) {
             //Dynamic - Pivot Day
             Debug::text('Dynamic - Pivot Date...', __FILE__, __LINE__, __METHOD__, 10);
             //Dynamic
             if (TTDate::getMonth($epoch) > $this->getMonth()) {
                 $year_modifier = 1;
             } else {
                 $year_modifier = 0;
             }
             $start_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch) + $year_modifier);
             $holiday_epoch = $start_epoch;
             $x = 0;
             $x_max = 100;
             if ($this->getPivotDayDirection() == 10 or $this->getPivotDayDirection() == 30) {
                 $direction_multiplier = -1;
             } else {
                 $direction_multiplier = 1;
             }
             $adjustment = 86400 * $direction_multiplier;
             // Adjust by 1 day before or after.
             if ($this->getPivotDayDirection() == 10 or $this->getPivotDayDirection() == 20) {
                 $holiday_epoch += $adjustment;
             }
             while ($this->getDayOfWeek() != TTDate::getDayOfWeek($holiday_epoch) and $x < $x_max) {
                 Debug::text('X: ' . $x . ' aTrying...' . TTDate::getDate('DATE+TIME', $holiday_epoch), __FILE__, __LINE__, __METHOD__, 10);
                 $holiday_epoch += $adjustment;
                 $x++;
             }
         }
     }
     $holiday_epoch = TTDate::getNearestWeekDay($holiday_epoch, $this->getAlwaysOnWeekDay());
     Debug::text('Next Date for: ' . $this->getName() . ' is: ' . TTDate::getDate('DATE+TIME', $holiday_epoch), __FILE__, __LINE__, __METHOD__, 10);
     return $holiday_epoch;
 }