1 date.class.inc public BackdropDateTime::setFuzzyDate($date, $format = NULL, $default = 'first')

Forces an incomplete date to be valid.

e.g. Add a valid year, month, and day if only the time has been defined.

Parameters

array|string $date: An array of date parts or a datetime string with values to be massaged into a valid date object.

string $format: (optional) The format of the date. Defaults to NULL.

string $default: (optional) If the fallback should use the first value of the date part, or the current value of the date part. Defaults to 'first'.

File

core/includes/date.class.inc, line 717

Class

BackdropDateTime
Extends PHP DateTime class for use with Backdrop.

Code

public function setFuzzyDate($date, $format = NULL, $default = 'first') {
  $timezone = $this->getTimeZone() ? $this->getTimeZone()->getName() : NULL;
  $comp = new BackdropDateTime($date, $timezone, $format);
  $arr = $comp->toArray(TRUE);
  foreach ($arr as $key => $value) {
    // Set to intval here and then test that it is still an integer.
    // Needed because sometimes valid integers come through as strings.
    $arr[$key] = $this->forceValid($key, intval($value), $default, $arr['month'], $arr['year']);
  }
  $this->setDate($arr['year'], $arr['month'], $arr['day']);
  $this->setTime($arr['hour'], $arr['minute'], $arr['second']);
}