コード例 #1
0
ファイル: Date.php プロジェクト: coolms/common
 /**
  * {@inheritDoc}
  */
 public function isValid($value)
 {
     if (null === $value && $this->isAllowNull()) {
         return true;
     }
     return parent::isValid($value);
 }
コード例 #2
0
ファイル: Date.php プロジェクト: Andyyang1981/pi
 /**
  * {@inheritDoc}
  */
 public function isValid($value)
 {
     if (!$value) {
         return true;
     }
     return parent::isValid($value);
 }
コード例 #3
0
ファイル: GroupInventory.php プロジェクト: arbi/MyCode
 /**
  * @param $apartmentGroupId
  * @param $from
  * @param $to
  * @param int $roomCount
  * @param $sort
  * @param $roomType
  * @return array
  */
 public function composeGroupAvailabilityForDateRange($apartmentGroupId, $from, $to, $roomCount = -1, $sort, $roomType)
 {
     /**
      * @var \DDD\Domain\Apartment\Inventory\GroupInventory[] $resultSet
      * @var \DDD\Dao\Booking\Booking $reservationDao
      */
     $dateValidator = new Date(['format' => 'Y-m-d']);
     if ($dateValidator->isValid($from) && $dateValidator->isValid($to)) {
         $apartmentService = $this->getServiceLocator()->get('service_apartment_general');
         $apartmentDao = new \DDD\Dao\Apartment\General($this->getServiceLocator(), 'DDD\\Domain\\Apartment\\Inventory\\GroupInventory');
         $reservationDao = $this->getServiceLocator()->get('dao_booking_booking');
         $overbookings = $reservationDao->getApartmentGroupOverbookingsForDateRange($apartmentGroupId, $from, $to, $roomCount, $roomType);
         $result = [];
         $dates = [];
         $existingDates = [];
         $resultSet = $apartmentDao->getGroupAvailabilityForDateRange($apartmentGroupId, $from, $to, $roomCount, $sort, $roomType);
         foreach ($resultSet as $row) {
             $apartmentId = $row->getId();
             $date = $row->getDate();
             if (!in_array($date, $existingDates)) {
                 array_push($existingDates, $date);
                 array_push($dates, ['raw' => $date, 'dayOfWeek' => date('D', strtotime($date)), 'day' => date('j', strtotime($date)), 'month' => date('n', strtotime($date))]);
             }
             if (isset($result[$apartmentId])) {
                 $result[$apartmentId][$date] = ['av' => $row->getAvailability(), 'reservation_data' => $row->getReservationData()];
             } else {
                 $balcony = !is_null($row->getAmenityId()) ? ' (B)' : '';
                 $bedroom = $row->getBedroom_count() . $balcony;
                 $result[$apartmentId] = ['id' => $row->getId(), 'name' => $row->getName(), 'floor' => $row->getFloor(), 'block' => $row->getBlock(), 'bedroom' => $bedroom, 'bathroom' => $row->getBathroom_count(), 'max_capacity' => $row->getMax_capacity(), 'unit_number' => $row->getUnit_number(), 'building_name' => $row->getBuildingName(), 'links' => $apartmentService->getWebsiteLink($row->getId()), $row->getDate() => ['av' => $row->getAvailability(), 'reservation_data' => $row->getReservationData()]];
             }
         }
         if (!empty($result)) {
             $result = array_values($result);
         }
         sort($dates);
         return ['list' => $result, 'days' => $dates, 'overbookings' => $overbookings];
     } else {
         return ['list' => [], 'days' => [], 'overbookings' => []];
     }
 }
コード例 #4
0
ファイル: DateStep.php プロジェクト: youprofit/casebox
 /**
  * Returns true if a date is within a valid step
  *
  * @param  string|int|\DateTime $value
  * @return bool
  * @throws Exception\InvalidArgumentException
  */
 public function isValid($value)
 {
     if (!parent::isValid($value)) {
         return false;
     }
     $valueDate = $this->convertToDateTime($value, false);
     // avoid duplicate errors
     $baseDate = $this->convertToDateTime($this->baseValue, false);
     $step = $this->getStep();
     // Same date?
     if ($valueDate == $baseDate) {
         return true;
     }
     // Optimization for simple intervals.
     // Handle intervals of just one date or time unit.
     $intervalParts = explode('|', $step->format('%y|%m|%d|%h|%i|%s'));
     $partCounts = array_count_values($intervalParts);
     $unitKeys = array('years', 'months', 'days', 'hours', 'minutes', 'seconds');
     $intervalParts = array_combine($unitKeys, $intervalParts);
     // Get absolute time difference
     $timeDiff = $valueDate->diff($baseDate, true);
     $diffParts = array_combine($unitKeys, explode('|', $timeDiff->format('%y|%m|%d|%h|%i|%s')));
     if (5 === $partCounts["0"]) {
         // Find the unit with the non-zero interval
         $intervalUnit = null;
         $stepValue = null;
         foreach ($intervalParts as $key => $value) {
             if (0 != $value) {
                 $intervalUnit = $key;
                 $stepValue = (int) $value;
                 break;
             }
         }
         // Check date units
         if (in_array($intervalUnit, array('years', 'months', 'days'))) {
             switch ($intervalUnit) {
                 case 'years':
                     if (0 == $diffParts['months'] && 0 == $diffParts['days'] && 0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         if ($diffParts['years'] % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
                 case 'months':
                     if (0 == $diffParts['days'] && 0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         $months = $diffParts['years'] * 12 + $diffParts['months'];
                         if ($months % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
                 case 'days':
                     if (0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         $days = $timeDiff->format('%a');
                         // Total days
                         if ($days % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
             }
             $this->error(self::NOT_STEP);
             return false;
         }
         // Check time units
         if (in_array($intervalUnit, array('hours', 'minutes', 'seconds'))) {
             // Simple test if $stepValue is 1.
             if (1 == $stepValue) {
                 if ('hours' === $intervalUnit && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                     return true;
                 } elseif ('minutes' === $intervalUnit && 0 == $diffParts['seconds']) {
                     return true;
                 } elseif ('seconds' === $intervalUnit) {
                     return true;
                 }
                 $this->error(self::NOT_STEP);
                 return false;
             }
             // Simple test for same day, when using default baseDate
             if ($baseDate->format('Y-m-d') == $valueDate->format('Y-m-d') && $baseDate->format('Y-m-d') == '1970-01-01') {
                 switch ($intervalUnit) {
                     case 'hours':
                         if (0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                             if ($diffParts['hours'] % $stepValue === 0) {
                                 return true;
                             }
                         }
                         break;
                     case 'minutes':
                         if (0 == $diffParts['seconds']) {
                             $minutes = $diffParts['hours'] * 60 + $diffParts['minutes'];
                             if ($minutes % $stepValue === 0) {
                                 return true;
                             }
                         }
                         break;
                     case 'seconds':
                         $seconds = $diffParts['hours'] * 60 * 60 + $diffParts['minutes'] * 60 + $diffParts['seconds'];
                         if ($seconds % $stepValue === 0) {
                             return true;
                         }
                         break;
                 }
                 $this->error(self::NOT_STEP);
                 return false;
             }
         }
     }
     return $this->fallbackIncrementalIterationLogic($baseDate, $valueDate, $intervalParts, $diffParts, $step);
 }
コード例 #5
0
ファイル: DateTest.php プロジェクト: bradley-holt/zf2
 /**
  * @ZF-6374
  */
 public function testUsingApplicationLocale()
 {
     \Zend\Registry::set('Zend_Locale', new \Zend\Locale\Locale('de'));
     $valid = new Validator\Date();
     $this->assertTrue($valid->isValid('10.April.2008'));
 }
コード例 #6
0
ファイル: DateStep.php プロジェクト: eltondias/Relogio
 /**
  * Returns true if a date is within a valid step
  *
  * @param  string|int|\DateTime $value
  * @return bool
  * @throws Exception\InvalidArgumentException
  */
 public function isValid($value)
 {
     parent::isValid($value);
     $this->setValue($value);
     $baseDate = $this->convertToDateTime($this->getBaseValue());
     $step = $this->getStep();
     // Parse the date
     try {
         $valueDate = $this->convertToDateTime($value);
     } catch (Exception\InvalidArgumentException $ex) {
         return false;
     }
     // Same date?
     if ($valueDate == $baseDate) {
         return true;
     }
     // Optimization for simple intervals.
     // Handle intervals of just one date or time unit.
     $intervalParts = explode('|', $step->format('%y|%m|%d|%h|%i|%s'));
     $partCounts = array_count_values($intervalParts);
     if (5 === $partCounts["0"]) {
         // Find the unit with the non-zero interval
         $unitKeys = array('years', 'months', 'days', 'hours', 'minutes', 'seconds');
         $intervalParts = array_combine($unitKeys, $intervalParts);
         $intervalUnit = null;
         $stepValue = null;
         foreach ($intervalParts as $key => $value) {
             if (0 != $value) {
                 $intervalUnit = $key;
                 $stepValue = (int) $value;
                 break;
             }
         }
         // Get absolute time difference
         $timeDiff = $valueDate->diff($baseDate, true);
         $diffParts = explode('|', $timeDiff->format('%y|%m|%d|%h|%i|%s'));
         $diffParts = array_combine($unitKeys, $diffParts);
         // Check date units
         if (in_array($intervalUnit, array('years', 'months', 'days'))) {
             switch ($intervalUnit) {
                 case 'years':
                     if (0 == $diffParts['months'] && 0 == $diffParts['days'] && 0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         if ($diffParts['years'] % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
                 case 'months':
                     if (0 == $diffParts['days'] && 0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         $months = $diffParts['years'] * 12 + $diffParts['months'];
                         if ($months % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
                 case 'days':
                     if (0 == $diffParts['hours'] && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                         $days = $timeDiff->format('%a');
                         // Total days
                         if ($days % $stepValue === 0) {
                             return true;
                         }
                     }
                     break;
             }
             $this->error(self::NOT_STEP);
             return false;
         }
         // Check time units
         if (in_array($intervalUnit, array('hours', 'minutes', 'seconds'))) {
             // Simple test if $stepValue is 1.
             if (1 == $stepValue) {
                 if ('hours' === $intervalUnit && 0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                     return true;
                 } elseif ('minutes' === $intervalUnit && 0 == $diffParts['seconds']) {
                     return true;
                 } elseif ('seconds' === $intervalUnit) {
                     return true;
                 }
             }
             // Simple test for same day, when using default baseDate
             if ($baseDate->format('Y-m-d') == $valueDate->format('Y-m-d') && $baseDate->format('Y-m-d') == '1970-01-01') {
                 switch ($intervalUnit) {
                     case 'hours':
                         if (0 == $diffParts['minutes'] && 0 == $diffParts['seconds']) {
                             if ($diffParts['hours'] % $stepValue === 0) {
                                 return true;
                             }
                         }
                         break;
                     case 'minutes':
                         if (0 == $diffParts['seconds']) {
                             $minutes = $diffParts['hours'] * 60 + $diffParts['minutes'];
                             if ($minutes % $stepValue === 0) {
                                 return true;
                             }
                         }
                         break;
                     case 'seconds':
                         $seconds = $diffParts['hours'] * 60 + $diffParts['minutes'] * 60 + $diffParts['seconds'];
                         if ($seconds % $stepValue === 0) {
                             return true;
                         }
                         break;
                 }
                 $this->error(self::NOT_STEP);
                 return false;
             }
         }
     }
     // Fall back to slower (but accurate) method for complex intervals.
     // Keep adding steps to the base date until a match is found
     // or until the value is exceeded.
     if ($baseDate < $valueDate) {
         while ($baseDate < $valueDate) {
             $baseDate->add($step);
             if ($baseDate == $valueDate) {
                 return true;
             }
         }
     } else {
         while ($baseDate > $valueDate) {
             $baseDate->sub($step);
             if ($baseDate == $valueDate) {
                 return true;
             }
         }
     }
     $this->error(self::NOT_STEP);
     return false;
 }
コード例 #7
0
ファイル: IsEarlier.php プロジェクト: remithomas/rt-extends
 /**
  * Validate a value
  * @param  string|array|int|DateTime $value
  * @return bool
  */
 public function isValid($value)
 {
     /// valid date
     $parentTest = parent::isValid($value);
     if (!$parentTest) {
         $this->error(self::FALSEFORMAT);
         return false;
     }
     // test if is later
     // timezone
     if (!$this->timezone != "") {
         $timezone = new \DateTimeZone($this->timezone);
         $dateA = DateTime::createFromFormat($this->format, $this->max, $timezone);
         $dateB = DateTime::createFromFormat($this->format, $this->value, $timezone);
     } else {
         $dateA = DateTime::createFromFormat($this->format, $this->max);
         $dateB = DateTime::createFromFormat($this->format, $this->value);
     }
     if ($dateA > $dateB) {
         return true;
     } else {
         $this->error(self::DATE_NOT_EARLIER);
         return false;
     }
 }
コード例 #8
0
ファイル: DateTest.php プロジェクト: razvansividra/pnlzf2-1
 /**
  * Ensures that the validator follows expected behavior
  *
  * @dataProvider datesDataProvider
  */
 public function testBasic($input, $format, $result)
 {
     $this->validator->setFormat($format);
     $this->assertEquals($result, $this->validator->isValid($input));
     $this->assertEquals($format, $this->validator->getFormat());
 }