You are here

function date_format_patterns in Date 7

Same name and namespace in other branches
  1. 5.2 date_api.module \date_format_patterns()
  2. 6.2 date_api.module \date_format_patterns()
  3. 6 date_api.module \date_format_patterns()
  4. 7.3 date_api/date_api.module \date_format_patterns()
  5. 7.2 date_api/date_api.module \date_format_patterns()

Array of regex replacement strings for date format elements. Used to allow input in custom formats. Based on work done for the Date module by Yves Chedemois (yched).

Return value

array of date() format letters and their regex equivalents.

1 call to date_format_patterns()
DateObject::parse in date_api/date_api.module

File

date_api/date_api.module, line 1002
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_format_patterns($strict = FALSE) {
  return array(
    'd' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    'm' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    'h' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    'H' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    'i' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    's' => '\\d{' . ($strict ? '2' : '1,2') . '}',
    'j' => '\\d{1,2}',
    'N' => '\\d',
    'S' => '\\w{2}',
    'w' => '\\d',
    'z' => '\\d{1,3}',
    'W' => '\\d{1,2}',
    'n' => '\\d{1,2}',
    't' => '\\d{2}',
    'L' => '\\d',
    'o' => '\\d{4}',
    'Y' => '-?\\d{1,6}',
    'y' => '\\d{2}',
    'B' => '\\d{3}',
    'g' => '\\d{1,2}',
    'G' => '\\d{1,2}',
    'e' => '\\w*',
    'I' => '\\d',
    'T' => '\\w*',
    'U' => '\\d*',
    'z' => '[+-]?\\d*',
    'O' => '[+-]?\\d{4}',
    //Using S instead of w and 3 as well as 4 to pick up non-ASCII chars like German umlaute
    'D' => '\\S{3,4}',
    'l' => '\\S*',
    'M' => '\\S{3,4}',
    'F' => '\\S*',
    'P' => '[+-]?\\d{2}\\:\\d{2}',
    'O' => '[+-]\\d{4}',
    'c' => '(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})([+-]?\\d{2}\\:\\d{2})',
    'r' => '(\\w{3}), (\\d{2})\\s(\\w{3})\\s(\\d{2,4})\\s(\\d{2}):(\\d{2}):(\\d{2})([+-]?\\d{4})?',
  );
}