Files
opensourcepos/application/helpers/dateformat_helper.php

133 lines
2.9 KiB
PHP

<?php
/*
* Matches each symbol of PHP date format standard
* with jQuery equivalent codeword
* @author Tristan Jahier
*/
function dateformat_jquery($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' => 'yy',
'y' => 'y',
// Time
'a' => 'tt',
'A' => 'TT',
'B' => '',
'g' => 'h',
'G' => 'H',
'h' => 'hh',
'H' => 'HH',
'i' => 'mm',
's' => 'ss',
'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;
}
function dateformat_bootstrap($php_format)
{
$SYMBOLS_MATCHING = array(
// Day
'd' => 'dd',
'D' => 'd',
'j' => 'd',
'l' => 'dd',
'N' => '',
'S' => '',
'w' => '',
'z' => '',
// Week
'W' => '',
// Month
'F' => 'MM',
'm' => 'mm',
'M' => 'M',
'n' => 'm',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => 'yyyy',
'y' => 'yy',
// Time
'a' => 'p',
'A' => 'P',
'B' => '',
'g' => 'H',
'G' => 'h',
'h' => 'HH',
'H' => 'hh',
'i' => 'ii',
's' => 'ss',
'u' => ''
);
$bootstrap_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) $bootstrap_format .= $php_format[$i];
else $bootstrap_format .= '\'' . $php_format[$i];
$escaping = true;
}
else
{
if($escaping) { $bootstrap_format .= "'"; $escaping = false; }
if(isset($SYMBOLS_MATCHING[$char]))
$bootstrap_format .= $SYMBOLS_MATCHING[$char];
else
$bootstrap_format .= $char;
}
}
return $bootstrap_format;
}
?>