You are here

function date_fuzzy_datetime in Date 6

Same name and namespace in other branches
  1. 5.2 date_api.module \date_fuzzy_datetime()
  2. 6.2 date_api.module \date_fuzzy_datetime()

Create valid datetime value from incomplete ISO dates or arrays.

3 calls to date_fuzzy_datetime()
date_convert in ./date_api.module
Date conversion helper function.
date_formatter_process in date/date.module
Helper function for creating formatted date arrays from a formatter.
date_local_date in date/date_elements.inc
Create local date object.

File

./date_api.module, line 970
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_fuzzy_datetime($date) {
  if (!is_array($date)) {
    $date = date_iso_array($date);
  }
  if (empty($date['year'])) {
    $date['year'] = date('Y');
  }
  if (empty($date['month'])) {
    $date['month'] = 1;
  }
  if (empty($date['day'])) {
    $date['day'] = 1;
  }
  $value = date_pad($date['year'], 4) . '-' . date_pad($date['month']) . '-' . date_pad($date['day']) . 'T' . date_pad($date['hour']) . ':' . date_pad($date['minute']) . ':' . date_pad($date['second']);
  return $value;
}