if (isset($data['date_stamp'])) {
    $data['date_stamp'] = TTDate::parseDateTime($data['date_stamp']);
}
$hf = new HolidayFactory();
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $hf->setId($data['id']);
        if (isset($data['holiday_policy_id'])) {
            $hf->setHolidayPolicyId($data['holiday_policy_id']);
        }
        //Set datestamp first.
        $hf->setDateStamp($data['date_stamp']);
        $hf->setName($data['name']);
        if ($hf->isValid()) {
            $hf->Save();
            Redirect::Page(URLBuilder::getURL(array('id' => $data['holiday_policy_id']), 'HolidayList.php'));
            break;
        }
    default:
        if (isset($id) and $id != '') {
            BreadCrumb::setCrumb($title);
            $hlf = new HolidayListFactory();
            $hlf->getByIdAndHolidayPolicyID($id, $holiday_policy_id);
            if ($hlf->getRecordCount() > 0) {
                foreach ($hlf as $h_obj) {
                    //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
                    $data = array('id' => $h_obj->getId(), 'holiday_policy_id' => $h_obj->getHolidayPolicyID(), 'date_stamp' => $h_obj->getDateStamp(), 'name' => $h_obj->getName(), 'created_date' => $h_obj->getCreatedDate(), 'created_by' => $h_obj->getCreatedBy(), 'updated_date' => $h_obj->getUpdatedDate(), 'updated_by' => $h_obj->getUpdatedBy(), 'deleted_date' => $h_obj->getDeletedDate(), 'deleted_by' => $h_obj->getDeletedBy());
 function createHoliday($company_id, $type, $date, $holiday_policy_id)
 {
     $hf = new HolidayFactory();
     switch ($type) {
         case 10:
             $hf->setHolidayPolicyId($holiday_policy_id);
             $hf->setDateStamp($date);
             $hf->setName('Test1');
             break;
     }
     if ($hf->isValid()) {
         $insert_id = $hf->Save();
         Debug::Text('Holiday ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         return $insert_id;
     }
     Debug::Text('Failed Creating Holiday!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 $recurring_holiday_ids = $hp_obj->getRecurringHoliday();
 if (is_array($recurring_holiday_ids) and count($recurring_holiday_ids) > 0) {
     Debug::Text('Found Recurring Holidays...', __FILE__, __LINE__, __METHOD__, 10);
     foreach ($recurring_holiday_ids as $recurring_holiday_id) {
         $rhlf = new RecurringHolidayListFactory();
         $rhlf->getById($recurring_holiday_id);
         if ($rhlf->getRecordCount() == 1) {
             $rh_obj = $rhlf->getCurrent();
             Debug::Text('Found Recurring Holiday: ' . $rh_obj->getName(), __FILE__, __LINE__, __METHOD__, 10);
             $next_holiday_date = $rh_obj->getNextDate($epoch);
             Debug::Text('Next Holiday Date: ' . TTDate::getDate('DATE+TIME', $next_holiday_date), __FILE__, __LINE__, __METHOD__, 10);
             if ($next_holiday_date <= $epoch + $offset) {
                 Debug::Text('Next Holiday Date is within Time Period (offset) adding...', __FILE__, __LINE__, __METHOD__, 10);
                 $hf = new HolidayFactory();
                 $hf->setHolidayPolicyId($hp_obj->getId());
                 $hf->setDateStamp($next_holiday_date);
                 $hf->setName($rh_obj->getName());
                 if ($hf->isValid()) {
                     $hf->Save();
                 }
             } else {
                 Debug::Text('Next Holiday Date is NOT within Time Period (offset)!', __FILE__, __LINE__, __METHOD__, 10);
             }
         }
     }
 }
 /*
 $end_date = NULL;
 
 $pay_period_schedule->createNextPayPeriod($end_date, $offset);