function createNextPayPeriod($end_date = NULL, $offset = NULL)
 {
     if ($end_date == NULL or $end_date == '') {
         $end_date = NULL;
     }
     if ($offset == NULL or $offset == '') {
         $offset = 86400;
         //24hrs
     }
     if ($this->getType() == 5) {
         return FALSE;
     }
     Debug::text('Current TimeZone: ' . TTDate::getTimeZone(), __FILE__, __LINE__, __METHOD__, 10);
     //Handle timezones in this function rather then getNextPayPeriod()
     //Because if we set the timezone back to the original in that function, it
     //gets written to the database in the "original" timezone, not the proper timezone.
     $this->setPayPeriodTimeZone();
     Debug::text('Pay Period TimeZone: ' . TTDate::getTimeZone(), __FILE__, __LINE__, __METHOD__, 10);
     Debug::text('End Date (' . $end_date . '): ' . TTDate::getDate('DATE+TIME', $end_date), __FILE__, __LINE__, __METHOD__, 10);
     $this->getNextPayPeriod($end_date);
     Debug::text('Next pay period starts: ' . TTDate::getDate('DATE+TIME', $this->getNextStartDate()), __FILE__, __LINE__, __METHOD__, 10);
     //If the start date is within 24hrs of now, insert the next pay period.
     if ($this->getNextStartDate() <= TTDate::getTime() + $offset) {
         Debug::text('Insert new pay period. Start Date: ' . $this->getNextStartDate() . ' End Date: ' . $this->getNextEndDate(), __FILE__, __LINE__, __METHOD__, 10);
         $ppf = new PayPeriodFactory();
         $ppf->setCompany($this->getCompany());
         $ppf->setPayPeriodSchedule($this->getId());
         $ppf->setStatus(10);
         $ppf->setStartDate($this->getNextStartDate());
         $ppf->setEndDate($this->getNextEndDate());
         $ppf->setTransactionDate($this->getNextTransactionDate());
         $ppf->setPrimary($this->getNextPrimary());
         $ppf->setEnableImportData(TRUE);
         //Import punches when creating new pay periods.
         if ($ppf->isValid()) {
             $new_pay_period_id = $ppf->Save();
             Debug::text('New Pay Period ID: ' . $new_pay_period_id, __FILE__, __LINE__, __METHOD__, 10);
             if ($new_pay_period_id != '') {
                 $this->setOriginalTimeZone();
                 return TRUE;
             } else {
                 Debug::text('aSaving Pay Period Failed!', __FILE__, __LINE__, __METHOD__, 10);
             }
         } else {
             Debug::text('bSaving Pay Period Failed!', __FILE__, __LINE__, __METHOD__, 10);
         }
     } else {
         Debug::text('***NOT inserting or changing status of new pay period yet, not within offset.', __FILE__, __LINE__, __METHOD__, 10);
     }
     $this->setOriginalTimeZone();
     return FALSE;
 }