You are here

function date_output_options in Date 5

Function to create an option list that will display various date and time formats

Parameters

$tz_handling - default is 'site': @param $illustration_date - an iso date to use for illustration of the date options default date for illustration: August 1 YYYY 2:05:10 PM

  • single digit months and days to see leading zeros
  • a month number different than the day number to see month and day positions
  • an afternoon time to illustrate 24 hours vs am/pm formats

@return array of date format strings for all date_date_options() and/or date_time_options() with a key of the format string and a value of the illustration date displayed in that format

File

./date.inc, line 1663
Date/time API functions

Code

function date_output_options($tz_handling = 'site', $illustration_date = NULL) {
  $illustration_date = $illustration_date ? $illustration_date : date_gmdate('Y', time()) . '-08-01T14:05:10';
  $date = date_make_date($illustration_date, date_get_timezone($tz_handling), 'local', DATE_ISO);

  // from system module, possible date formats
  $dateshort = array(
    'Y-m-d H:i',
    'm/d/Y - H:i',
    'd/m/Y - H:i',
    'Y/m/d - H:i',
    'd.m.Y - H:i',
    'm/d/Y - g:ia',
    'd/m/Y - g:ia',
    'Y/m/d - g:ia',
    'M j Y - H:i',
    'j M Y - H:i',
    'Y M j - H:i',
    'M j Y - g:ia',
    'j M Y - g:ia',
    'Y M j - g:ia',
  );
  $datemedium = array(
    'D, Y-m-d H:i',
    'D, m/d/Y - H:i',
    'D, d/m/Y - H:i',
    'D, Y/m/d - H:i',
    'F j, Y - H:i',
    'j F, Y - H:i',
    'Y, F j - H:i',
    'D, m/d/Y - g:ia',
    'D, d/m/Y - g:ia',
    'D, Y/m/d - g:ia',
    'F j, Y - g:ia',
    'j F Y - g:ia',
    'Y, F j - g:ia',
    'j. F Y - G:i',
  );
  $datelong = array(
    'l, F j, Y - H:i',
    'l, j F, Y - H:i',
    'l, Y,  F j - H:i',
    'l, F j, Y - g:ia',
    'l, j F Y - g:ia',
    'l, Y,  F j - g:ia',
    'l, j. F Y - G:i',
  );
  $datestrings = array_merge($dateshort, $datemedium, $datelong);
  $view = array();
  foreach ($datestrings as $datestring) {
    $parts = explode(' - ', $datestring);

    // create an option that shows date only without time
    $view[trim($parts[0])] = date_show_date($date, trim($parts[0]));
    $view[$datestring] = date_show_date($date, $datestring);
  }
  asort($view);
  return $view;
}