예제 #1
0
 /**
  * Converts the given $date to a valid PHP's DateTime object using a jQuery's
  * date/time $format.
  *
  * @param string $format A jQuery's date/time format. e.g. `'today is:' yy-mm-dd`
  * @param string $date A date formatted using $format. e.g. `today is: 2015-01-30`
  * @return \DateTime|false Date object on success, false on error
  */
 public static function createFromFormat($format, $date)
 {
     if (preg_match_all("/'([^']+)'/", $format, $matches)) {
         foreach ($matches[1] as $literal) {
             $date = str_replace($literal, '', $date);
         }
         $date = preg_replace('/\\s{2,}/', ' ', $date);
         // remove double spaces
     }
     $date = trim($date);
     $format = DateToolbox::normalizeFormat($format);
     return date_create_from_format($format, $date);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function validateSettings(FieldInstance $instance, array $settings, Validator $validator)
 {
     $validator->allowEmpty('time_format')->add('time_format', 'validTimeFormat', ['rule' => function ($value, $context) use($settings) {
         if (empty($settings['timepicker'])) {
             return true;
         }
         return DateToolbox::validateTimeFormat($value);
     }, 'message' => __d('field', 'Invalid time format.')])->allowEmpty('format')->add('format', 'validDateFormat', ['rule' => function ($value, $context) {
         return DateToolbox::validateDateFormat($value);
     }, 'message' => __d('field', 'Invalid date format.')]);
 }