/**
  * Запуск валидации
  *
  * @param $sValue	Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.root.engine') . '/lib/external/DateTime/DateTimeParser.php';
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0));
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate_date_format_invalid', null, false), 'msg');
     }
     return true;
 }
예제 #2
0
 /**
  * Запуск валидации
  *
  * @param mixed $sValue    Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if (is_array($sValue)) {
         return $this->getMessage(E::ModuleLang()->Get('validate_date_format_invalid', null, false), 'msg');
     }
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     F::IncludeLib('DateTime/DateTimeParser.php');
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0));
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage(E::ModuleLang()->Get('validate_date_format_invalid', null, false), 'msg');
     }
     return true;
 }
 /**
  * Запуск валидации
  *
  * @param mixed $sValue Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if (is_array($sValue)) {
         return $this->getMessage($this->Lang_Get('validate.date.format_invalid', null, false), 'msg');
     }
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.framework.libs_vendor.server') . '/DateTime/DateTimeParser.php';
     $aFormats = is_string($this->format) ? array($this->format) : $this->format;
     $bValid = false;
     foreach ($aFormats as $sFormat) {
         $iTimestamp = DateTimeParser::parse($sValue, $sFormat);
         if ($iTimestamp !== false) {
             $bValid = true;
             break;
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate.date.format_invalid', null, false), 'msg');
     }
     return true;
 }
예제 #4
0
 /**
  * Creates the iterator
  *
  * You should pass a VCALENDAR component, as well as the UID of the event
  * we're going to traverse.
  *
  * @param Component $vcal
  * @param string|null $uid
  */
 public function __construct(Component $vcal, $uid = null)
 {
     if (is_null($uid)) {
         if ($vcal instanceof Component\VCalendar) {
             throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
         }
         $components = array($vcal);
         $uid = (string) $vcal->uid;
     } else {
         $components = $vcal->select('VEVENT');
     }
     foreach ($components as $component) {
         if ((string) $component->uid == $uid) {
             if (isset($component->{'RECURRENCE-ID'})) {
                 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
                 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
             } else {
                 $this->baseEvent = $component;
             }
         }
     }
     if (!$this->baseEvent) {
         // No base event was found. CalDAV does allow cases where only
         // overridden instances are stored.
         //
         // In this barticular case, we're just going to grab the first
         // event and use that instead. This may not always give the
         // desired result.
         if (!count($this->overriddenEvents)) {
             throw new \InvalidArgumentException('Could not find an event with uid: ' . $uid);
         }
         ksort($this->overriddenEvents, SORT_NUMERIC);
         $this->baseEvent = array_shift($this->overriddenEvents);
     }
     $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
     $this->endDate = null;
     if (isset($this->baseEvent->DTEND)) {
         $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
     } else {
         $this->endDate = clone $this->startDate;
         if (isset($this->baseEvent->DURATION)) {
             $this->endDate->add(DateTimeParser::parse((string) $this->baseEvent->DURATION));
         } elseif (!$this->baseEvent->DTSTART->hasTime()) {
             $this->endDate->modify('+1 day');
         }
     }
     $this->currentDate = clone $this->startDate;
     $rrule = $this->baseEvent->RRULE;
     // If no rrule was specified, we create a default setting
     if (!$rrule) {
         $this->frequency = 'daily';
         $this->count = 1;
     } else {
         foreach ($rrule->getParts() as $key => $value) {
             switch ($key) {
                 case 'FREQ':
                     if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
                         throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
                     }
                     $this->frequency = strtolower($value);
                     break;
                 case 'UNTIL':
                     $this->until = DateTimeParser::parse($value);
                     // In some cases events are generated with an UNTIL=
                     // parameter before the actual start of the event.
                     //
                     // Not sure why this is happening. We assume that the
                     // intention was that the event only recurs once.
                     //
                     // So we are modifying the parameter so our code doesn't
                     // break.
                     if ($this->until < $this->baseEvent->DTSTART->getDateTime()) {
                         $this->until = $this->baseEvent->DTSTART->getDateTime();
                     }
                     break;
                 case 'COUNT':
                     $this->count = (int) $value;
                     break;
                 case 'INTERVAL':
                     $this->interval = (int) $value;
                     if ($this->interval < 1) {
                         throw new \InvalidArgumentException('INTERVAL in RRULE must be a positive integer!');
                     }
                     break;
                 case 'BYSECOND':
                     $this->bySecond = (array) $value;
                     break;
                 case 'BYMINUTE':
                     $this->byMinute = (array) $value;
                     break;
                 case 'BYHOUR':
                     $this->byHour = (array) $value;
                     break;
                 case 'BYDAY':
                     $this->byDay = (array) $value;
                     break;
                 case 'BYMONTHDAY':
                     $this->byMonthDay = (array) $value;
                     break;
                 case 'BYYEARDAY':
                     $this->byYearDay = (array) $value;
                     break;
                 case 'BYWEEKNO':
                     $this->byWeekNo = (array) $value;
                     break;
                 case 'BYMONTH':
                     $this->byMonth = (array) $value;
                     break;
                 case 'BYSETPOS':
                     $this->bySetPos = (array) $value;
                     break;
                 case 'WKST':
                     $this->weekStart = strtoupper($value);
                     break;
             }
         }
     }
     // Parsing exception dates
     if (isset($this->baseEvent->EXDATE)) {
         foreach ($this->baseEvent->EXDATE as $exDate) {
             foreach (explode(',', (string) $exDate) as $exceptionDate) {
                 $this->exceptionDates[] = DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
             }
         }
     }
 }
 /**
  * Creates the iterator
  *
  * You should pass a VCALENDAR component, as well as the UID of the event
  * we're going to traverse.
  *
  * @param Component $vcal
  * @param string|null $uid
  */
 public function __construct(Component $vcal, $uid = null)
 {
     if (is_null($uid)) {
         if ($vcal->name === 'VCALENDAR') {
             throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
         }
         $components = array($vcal);
         $uid = (string) $vcal->uid;
     } else {
         $components = $vcal->select('VEVENT');
     }
     foreach ($components as $component) {
         if ((string) $component->uid == $uid) {
             if (isset($component->{'RECURRENCE-ID'})) {
                 $this->overriddenEvents[$component->DTSTART->getDateTime()->getTimeStamp()] = $component;
                 $this->overriddenDates[] = $component->{'RECURRENCE-ID'}->getDateTime();
             } else {
                 $this->baseEvent = $component;
             }
         }
     }
     if (!$this->baseEvent) {
         throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid);
     }
     $this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
     $this->endDate = null;
     if (isset($this->baseEvent->DTEND)) {
         $this->endDate = clone $this->baseEvent->DTEND->getDateTime();
     } else {
         $this->endDate = clone $this->startDate;
         if (isset($this->baseEvent->DURATION)) {
             $this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value));
         } elseif ($this->baseEvent->DTSTART->getDateType() === Property\DateTime::DATE) {
             $this->endDate->modify('+1 day');
         }
     }
     $this->currentDate = clone $this->startDate;
     $rrule = (string) $this->baseEvent->RRULE;
     $parts = explode(';', $rrule);
     // If no rrule was specified, we create a default setting
     if (!$rrule) {
         $this->frequency = 'daily';
         $this->count = 1;
     } else {
         foreach ($parts as $part) {
             list($key, $value) = explode('=', $part, 2);
             switch (strtoupper($key)) {
                 case 'FREQ':
                     if (!in_array(strtolower($value), array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
                         throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
                     }
                     $this->frequency = strtolower($value);
                     break;
                 case 'UNTIL':
                     $this->until = DateTimeParser::parse($value);
                     // In some cases events are generated with an UNTIL=
                     // parameter before the actual start of the event.
                     //
                     // Not sure why this is happening. We assume that the
                     // intention was that the event only recurs once.
                     //
                     // So we are modifying the parameter so our code doesn't
                     // break.
                     if ($this->until < $this->baseEvent->DTSTART->getDateTime()) {
                         $this->until = $this->baseEvent->DTSTART->getDateTime();
                     }
                     break;
                 case 'COUNT':
                     $this->count = (int) $value;
                     break;
                 case 'INTERVAL':
                     $this->interval = (int) $value;
                     if ($this->interval < 1) {
                         throw new \InvalidArgumentException('INTERVAL in RRULE must be a positive integer!');
                     }
                     break;
                 case 'BYSECOND':
                     $this->bySecond = explode(',', $value);
                     break;
                 case 'BYMINUTE':
                     $this->byMinute = explode(',', $value);
                     break;
                 case 'BYHOUR':
                     $this->byHour = explode(',', $value);
                     break;
                 case 'BYDAY':
                     $this->byDay = explode(',', strtoupper($value));
                     break;
                 case 'BYMONTHDAY':
                     $this->byMonthDay = explode(',', $value);
                     break;
                 case 'BYYEARDAY':
                     $this->byYearDay = explode(',', $value);
                     break;
                 case 'BYWEEKNO':
                     $this->byWeekNo = explode(',', $value);
                     break;
                 case 'BYMONTH':
                     $this->byMonth = explode(',', $value);
                     break;
                 case 'BYSETPOS':
                     $this->bySetPos = explode(',', $value);
                     break;
                 case 'WKST':
                     $this->weekStart = strtoupper($value);
                     break;
             }
         }
     }
     // Parsing exception dates
     if (isset($this->baseEvent->EXDATE)) {
         foreach ($this->baseEvent->EXDATE as $exDate) {
             foreach (explode(',', (string) $exDate) as $exceptionDate) {
                 $this->exceptionDates[] = DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
             }
         }
     }
 }
예제 #6
0
 /**
  * Create a new Date object from a parsable date.
  *
  * @param string|int The date to parse
  * @param string|int The time to parse (ignored, use the DateTimeParser for time parsing)
  *
  * @return Date
  */
 public function parse($date, $time = null)
 {
     $result = parent::parse($date, 0);
     return new Date($result->timestamp());
 }
예제 #7
0
 /**
  * Запуск валидации
  *
  * @param mixed $sValue    Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     F::IncludeLib('DateTime/DateTimeParser.php');
     if ($this->type === 'integer') {
         $bValid = preg_match('/^[-+]?[0-9]+$/', trim($sValue));
     } else {
         if ($this->type === 'float') {
             $bValid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($sValue));
         } else {
             if ($this->type === 'date') {
                 $bValid = DateTimeParser::parse($sValue, $this->dateFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
             } else {
                 if ($this->type === 'time') {
                     $bValid = DateTimeParser::parse($sValue, $this->timeFormat) !== false;
                 } else {
                     if ($this->type === 'datetime') {
                         $bValid = DateTimeParser::parse($sValue, $this->datetimeFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
                     } else {
                         if ($this->type === 'array') {
                             $bValid = is_array($sValue);
                         } else {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     if (!$bValid) {
         return $this->getMessage(E::ModuleLang()->Get('validate_type_error', null, false), 'msg', array('type' => $this->type));
     }
     return true;
 }
 /**
  * Запуск валидации
  *
  * @param mixed $sValue Данные для валидации
  *
  * @return bool|string
  */
 public function validate($sValue)
 {
     if ($this->allowEmpty && $this->isEmpty($sValue)) {
         return true;
     }
     require_once Config::Get('path.framework.libs_vendor.server') . '/DateTime/DateTimeParser.php';
     if ($this->type === 'integer') {
         $bValid = preg_match('/^[-+]?[0-9]+$/', trim($sValue));
     } else {
         if ($this->type === 'float') {
             $bValid = preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($sValue));
         } else {
             if ($this->type === 'date') {
                 $bValid = DateTimeParser::parse($sValue, $this->dateFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
             } else {
                 if ($this->type === 'time') {
                     $bValid = DateTimeParser::parse($sValue, $this->timeFormat) !== false;
                 } else {
                     if ($this->type === 'datetime') {
                         $bValid = DateTimeParser::parse($sValue, $this->datetimeFormat, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0)) !== false;
                     } else {
                         if ($this->type === 'array') {
                             $bValid = is_array($sValue);
                         } else {
                             return true;
                         }
                     }
                 }
             }
         }
     }
     if (!$bValid) {
         return $this->getMessage($this->Lang_Get('validate.type.error', null, false), 'msg', array('type' => $this->type));
     }
     return true;
 }
예제 #9
0
 /**
  * Create a new DateTime object from a parsable date/time.
  *
  * @param string|int $date The date to parse
  * @param string|int $time The time to parse
  *
  * @return static
  */
 public static function parse($date, $time = null)
 {
     $parser = new DateTimeParser();
     $parser->addDefaultParsers();
     return $parser->parse($date, $time);
 }