Checks if value is date or time and if it fits in interval
@param string $field
@param string [string] $details
@param string $label
@param string $message
@return boolean
@throws \Exception
542989
protected function filterDate($field, $details, $label, $message) {
        if (false != ($date = @strtotime($this->getValue($field)))) {
            if (isset($details['min']) && $date < $details['min']) {
                throw new \Exception($message ? $message : $this->translate("Date must be bigger than $details[min]!"));
            }
            if (isset($details['max']) && $date > $details['max']) {
                throw new \Exception($message ? $message : $this->translate("Date must be smaller than $details[min]!"));
            }

            if (isset($details['format'])) {
                $this->setValue($field, date($details['format'], $date));
            }

            return true;
        }
        throw new \Exception($message ? $message : $this->translate("{$this->getValue($field)} is not a date!"));
    }
1048083
public static boolean hasTimestamp(final MessageOrBuilder messageOrBuilder) {
        try {
            final FieldDescriptor fieldDescriptor = ProtoBufFieldProcessor.getFieldDescriptor(messageOrBuilder, TIMESTAMP_FIELD_NAME);
            return messageOrBuilder.hasField(fieldDescriptor);
        } catch (NotAvailableException ex) {
            return false;
        }
    }
792831
public static function checkDatetimeFormat($field, $format, $msg)
    {
        $date = date($format, strtotime($field));
        if ($field !== $date) {
            throw new MsgException($msg);
        }
    }
31846
protected function setErrorInteger($field, $label)
    {
        $error = $this->translation->text('@field must be integer', array('@field' => $label));
        return $this->setError($field, $error);
    }
44572
protected function filterDigit($field, $details, $label, $message) {
        if (ctype_digit($this->getValue($field))) {
            return true;
        }
        throw new \Exception($message ? $message : $this->translate("$label must be digit!"));
    }
467411
public function formatTime($field, $value, array $options)
    {
        if ($value === null) {
            return $this->Html->label(__d('crud', 'N/A'), ['type' => 'info']);
        }
        $format = isset($options['format']) ? $options['format'] : null;

        if (is_int($value) || is_string($value) || $value instanceof DateTime || $value instanceof DateTimeImmutable) {
            return $this->Time->nice($value, $format);
        }

        return $this->Html->label(__d('crud', 'N/A'), ['type' => 'info']);
    }
447013
public function error(string $field, string $message, array $params = [])
    {
        $message = $this->checkAndSetLabel($field, $message, $params);

        $values = [];
        // Printed values need to be in string format
        foreach ($params as $param) {
            if (\is_array($param)) {
                $param = "['" . implode("', '", $param) . "']";
            } elseif ($param instanceof \DateTime) {
                $param = $param->format('Y-m-d');
            } elseif (\is_object($param)) {
                $param = \get_class($param);
            }

            // Use custom label instead of field name if set
            if (\is_string($params[0]) && isset($this->_labels[$param])) {
                $param = $this->_labels[$param];
            }
            $values[] = $param;
        }

        $this->_errors[$field][] = \vsprintf($message, $values);
    }
660244
public boolean isSet(_Fields field) {
    if (field == null) {
      throw new java.lang.IllegalArgumentException();
    }

    switch (field) {
    case TIMESTAMP:
      return isSetTimestamp();
    case VALUE:
      return isSetValue();
    case HOST:
      return isSetHost();
    }
    throw new java.lang.IllegalStateException();
  }
261602
protected function validate_date($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        $cdate1 = date('Y-m-d', strtotime($input[$field]));
        $cdate2 = date('Y-m-d H:i:s', strtotime($input[$field]));

        if ($cdate1 != $input[$field] && $cdate2 != $input[$field]) {
            return array(
                'field' => $field,
                'value' => $input[$field],
                'rule' => __FUNCTION__,
                'param' => $param,
            );
        }
    }
147959
private void setField(final Calendar calendar, final int field, final TemporalAccessor temporalAccessor,
			final ChronoField chronoField, final int offset, final int def) {
		calendar.set(field, temporalAccessor.isSupported(chronoField) ? temporalAccessor.get(chronoField) + offset
				: def);
	}
544490
private static void appendDate(StringBuilder message)
    {
        final String date = DATE_TIME_FORMAT.format(Calendar.getInstance().getTime());
        message.append(date);
        message.append(Constant.SPACE);
    }
306677
protected function evalDatetimeTypeValue($record, $column, $value)
    {
        if ($value === null) {
            return null;
        }

        $dateTime = $this->validateDateTimeValue($value, $column);

        if ($column->format !== null) {
            $value = $dateTime->format($column->format);
        }
        else {
            $value = $dateTime->toDayDateTimeString();
        }

        $options = [
            'defaultValue' => $value,
            'format' => $column->format,
            'formatAlias' => 'dateTimeLongMin'
        ];

        if (!empty($column->config['ignoreTimezone'])) {
            $options['ignoreTimezone'] = true;
        }

        return Backend::dateTime($dateTime, $options);
    }
518352
protected function validateTimestamp($value, ValidationField $field) {
        if (is_numeric($value) && $value > 0) {
            $result = (int)$value;
        } elseif (is_string($value) && $ts = strtotime($value)) {
            $result = $ts;
        } else {
            $field->addTypeError($value, 'timestamp');
            $result = Invalid::value();
        }
        return $result;
    }
117249
private void writeDateField(String fieldName, Object value) throws IOException
   {
      if (value instanceof String)
      {
         m_writer.writeNameValuePair(fieldName + "_text", (String) value);
      }
      else
      {
         Date val = (Date) value;
         m_writer.writeNameValuePair(fieldName, val);
      }
   }
1325737
public function postMessage($sender, $recipient, $message)
    {
        if (!isset($this->database[$recipient])) {
            $this->database[$recipient] = [];
        } elseif ($this->maxMessages
            && count($this->database[$recipient]) >= $this->maxMessages) {
            return false;
        }

        $this->database[$recipient][] = [
            'timestamp' => date('Y-m-d H:i:s'),
            'sender' => $sender,
            'message' => $message,
        ];

        return true;
    }
1167864
protected function validateDatetime($value, ValidationField $field) {
        if ($value instanceof \DateTimeInterface) {
            // do nothing, we're good
        } elseif (is_string($value) && $value !== '' && !is_numeric($value)) {
            try {
                $dt = new \DateTimeImmutable($value);
                if ($dt) {
                    $value = $dt;
                } else {
                    $value = null;
                }
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } elseif (is_int($value) && $value > 0) {
            try {
                $value = new \DateTimeImmutable('@'.(string)round($value));
            } catch (\Throwable $ex) {
                $value = Invalid::value();
            }
        } else {
            $value = Invalid::value();
        }

        if (Invalid::isInvalid($value)) {
            $field->addTypeError($value, 'date/time');
        }
        return $value;
    }
9586
public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case TIMESTAMP:
      return isSetTimestamp();
    case SUPER_COLUMN:
      return isSetSuper_column();
    case PREDICATE:
      return isSetPredicate();
    }
    throw new IllegalStateException();
  }