Exemple #1
0
 /**
  * Prepares the list data
  */
 public function prepareVars()
 {
     $this->vars['name'] = $this->formField->getName();
     if ($value = $this->getLoadValue()) {
         $value = DateTimeHelper::makeCarbon($value, false);
         $value = $value instanceof Carbon ? $value->toDateTimeString() : $value;
     }
     /*
      * Display alias, used by preview mode
      */
     if ($this->mode == 'time') {
         $formatAlias = 'time';
     } elseif ($this->mode == 'date') {
         $formatAlias = 'dateLong';
     } else {
         $formatAlias = 'dateTimeLong';
     }
     $this->vars['formatAlias'] = $formatAlias;
     $this->vars['value'] = $value ?: '';
     $this->vars['field'] = $this->formField;
     $this->vars['mode'] = $this->mode;
     $this->vars['minDate'] = $this->minDate;
     $this->vars['maxDate'] = $this->maxDate;
 }
Exemple #2
0
 /**
  * Validates a column type as a date
  */
 protected function validateDateTimeValue($value, $column)
 {
     $value = DateTimeHelper::instance()->makeCarbon($value, false);
     if (!$value instanceof Carbon) {
         throw new ApplicationException(Lang::get('backend::lang.list.invalid_column_datetime', ['column' => $column->columnName]));
     }
     return $value;
 }
 /**
  * Process as time as current tense (Today at 0:00)
  */
 protected function evalTimetenseTypeValue($record, $column, $value)
 {
     if ($value === null) {
         return null;
     }
     $value = $this->validateDateTimeValue($value, $column);
     return DateTimeHelper::timeTense($value);
 }
Exemple #4
0
 /**
  * Returns the HTML for a date formatted in the backend.
  * Supported for formatAlias:
  *   time             -> 6:28 AM
  *   timeLong         -> 6:28:01 AM
  *   date             -> 04/23/2016
  *   dateMin          -> 4/23/2016
  *   dateLong         -> April 23, 2016
  *   dateLongMin      -> Apr 23, 2016
  *   dateTime         -> April 23, 2016 6:28 AM
  *   dateTimeMin      -> Apr 23, 2016 6:28 AM
  *   dateTimeLong     -> Saturday, April 23, 2016 6:28 AM
  *   dateTimeLongMin  -> Sat, Apr 23, 2016 6:29 AM
  */
 public function dateTime($dateTime, $options = [])
 {
     extract(array_merge(['defaultValue' => '', 'format' => null, 'formatAlias' => null, 'jsFormat' => null, 'timeTense' => false, 'timeSince' => false], $options));
     $carbon = DateTimeHelper::makeCarbon($dateTime);
     if ($jsFormat !== null) {
         $format = $jsFormat;
     } else {
         $format = DateTimeHelper::momentFormat($format);
     }
     $attributes = ['datetime' => $carbon, 'data-datetime-control' => 1];
     if ($timeTense) {
         $attributes['data-time-tense'] = 1;
     } elseif ($timeSince) {
         $attributes['data-time-since'] = 1;
     } elseif ($format) {
         $attributes['data-format'] = $format;
     } elseif ($formatAlias) {
         $attributes['data-format-alias'] = $formatAlias;
     }
     return '<time' . Html::attributes($attributes) . '>' . e($defaultValue) . '</time>' . PHP_EOL;
 }
Exemple #5
0
 /**
  * Convert PHP format to JS format
  */
 protected function getDateFormatMoment()
 {
     if ($this->format) {
         return DateTimeHelper::momentFormat($this->format);
     }
 }