You are here

function calendar_system_convert_date_format_from_php_to_js in Calendar Systems 7.2

Same name and namespace in other branches
  1. 8 calendar_systems.helpers.inc \calendar_system_convert_date_format_from_php_to_js()
  2. 7 calendar_systems.helpers.inc \calendar_system_convert_date_format_from_php_to_js()

Parameters

$format:

1 call to calendar_system_convert_date_format_from_php_to_js()
calendar_systems_attach_js_date_picker in ./calendar_systems.module

File

./calendar_systems.helpers.inc, line 543

Code

function calendar_system_convert_date_format_from_php_to_js($php_format) {
  $SYMBOLS_MATCHING = array(
    // Day
    'd' => 'dd',
    'D' => 'D',
    'j' => 'd',
    'l' => 'DD',
    'N' => '',
    'S' => '',
    'w' => '',
    'z' => 'o',
    // Week
    'W' => '',
    // Month
    'F' => 'MM',
    'm' => 'mm',
    'M' => 'M',
    'n' => 'm',
    't' => '',
    // Year
    'L' => '',
    'o' => '',
    'Y' => 'yyyy',
    'y' => 'yy',
    // Time
    'a' => '',
    'A' => '',
    'B' => '',
    'g' => '',
    'G' => '',
    'h' => '',
    'H' => '',
    'i' => '',
    's' => '',
    'u' => '',
  );
  $jqueryui_format = "";
  $escaping = false;
  for ($i = 0; $i < strlen($php_format); $i++) {
    $char = $php_format[$i];
    if ($char === '\\') {

      // PHP date format escaping character
      $i++;
      if ($escaping) {
        $jqueryui_format .= $php_format[$i];
      }
      else {
        $jqueryui_format .= '\'' . $php_format[$i];
      }
      $escaping = true;
    }
    else {
      if ($escaping) {
        $jqueryui_format .= "'";
        $escaping = false;
      }
      if (isset($SYMBOLS_MATCHING[$char])) {
        $jqueryui_format .= $SYMBOLS_MATCHING[$char];
      }
      else {
        $jqueryui_format .= $char;
      }
    }
  }
  return $jqueryui_format;
}