static function findOrInsertUserDate($user_id, $date, $timezone = NULL)
 {
     $date = TTDate::getMiddleDayEpoch($date);
     //Use mid day epoch so the timezone conversion across DST doesn't affect the date.
     if ($timezone == NULL) {
         //Find the employees preferred timezone, base the user date off that instead of the pay period timezone,
         //as it can be really confusing to the user if they punch in at 10AM on Sept 27th, but it records as Sept 26th because
         //the PP Schedule timezone is 12hrs different or something.
         $uplf = new UserPreferenceListFactory();
         $uplf->getByUserID($user_id);
         if ($uplf->getRecordCount() > 0) {
             $timezone = $uplf->getCurrent()->getTimeZone();
         }
     }
     $date = TTDate::convertTimeZone($date, $timezone);
     Debug::text(' Using TimeZone: ' . $timezone . ' Date: ' . TTDate::getDate('DATE+TIME', $date) . '(' . $date . ')', __FILE__, __LINE__, __METHOD__, 10);
     $udlf = new UserDateListFactory();
     $udlf->getByUserIdAndDate($user_id, $date);
     if ($udlf->getRecordCount() == 1) {
         $id = $udlf->getCurrent()->getId();
         Debug::text(' Found Already Existing User Date ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
         return $id;
     } elseif ($udlf->getRecordCount() == 0) {
         Debug::text(' Inserting new UserDate row.', __FILE__, __LINE__, __METHOD__, 10);
         //Insert new row
         $udf = new UserDateFactory();
         $udf->setUser($user_id);
         $udf->setDateStamp($date);
         $udf->setPayPeriod();
         if ($udf->isValid()) {
             return $udf->Save();
         } else {
             Debug::text(' INVALID user date row. Pay Period Locked?', __FILE__, __LINE__, __METHOD__, 10);
         }
     } elseif ($udlf->getRecordCount() > 1) {
         Debug::text(' More then 1 user date row was detected!!: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     }
     Debug::text(' Cant find or insert User Date ID. User ID: ' . $user_id . ' Date: ' . $date, __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }