You are here

function date_strip_granularity in Date 5

Strip date parts that are not in the granularity array out of a date format string.

1 call to date_strip_granularity()
theme_date_formatter in ./date.module
Theme date formatter.

File

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

Code

function date_strip_granularity($format, $granularity) {
  $replace = array();
  foreach (date_nongranularity_array($granularity) as $element) {
    switch ($element) {
      case 'D':
        $replace = array_merge($replace, array(
          'l,',
          'l',
          'D,',
          'D-',
          'D/',
          'D',
          'd,',
          'd-',
          'd/',
          'd',
          'j,',
          'j-',
          'j/',
          'j',
        ));
        break;
      case 'M':
        $replace = array_merge($replace, array(
          'F,',
          'F-',
          'F/',
          'F',
          'M,',
          'M-',
          'M/',
          'M',
          'm,',
          'm-',
          'm/',
          'm',
          'n,',
          'n-',
          'n/',
          'n',
        ));
        break;
      case 'H':
        $replace = array_merge($replace, array(
          'H:',
          'H',
          'h:',
          'h',
          'G:',
          'g:',
          'g',
          'a',
          'A',
          ' - ',
        ));
        break;
      case 'N':
        $replace = array_merge($replace, array(
          'i:',
          'i',
        ));
        break;
      case 'S':
        $replace = array_merge($replace, array(
          's',
        ));
        break;
    }
  }
  return str_replace($replace, '', $format);
}