17     public function formatDBDate($sDBDateIn, $blForceEnglishRet = 
false)
 
   25         if ($blForceEnglishRet && $oStr->strstr($sDBDateIn, 
'-')) {
 
   29         if ($this->
isEmptyDate($sDBDateIn) && $sDBDateIn != 
'-') {
 
   31         } elseif ($sDBDateIn == 
'-') {
 
   32             return '0000-00-00 00:00:00';
 
   36         if (is_numeric($sDBDateIn)) {
 
   38             $sNew = substr($sDBDateIn, 0, 4) . 
'-' . substr($sDBDateIn, 4, 2) . 
'-' . substr($sDBDateIn, 6, 2) . 
' ';
 
   40             if (strlen($sDBDateIn) > 8) {
 
   41                 $sNew .= substr($sDBDateIn, 8, 2) . 
':' . substr($sDBDateIn, 10, 2) . 
':' . substr($sDBDateIn, 12, 2);
 
   48         $aData = explode(
' ', trim($sDBDateIn));
 
   51         $sTime = (isset($aData[1]) && $oStr->strstr($aData[1], 
':')) ? $aData[1] : 
'';
 
   52         $aTime = $sTime ? explode(
':', $sTime) : array(0, 0, 0);
 
   55         $sDate = isset($aData[0]) ? $aData[0] : 
'';
 
   56         $aDate = preg_split(
'/[\/.-]/', $sDate);
 
   60             $sFormat = $blForceEnglishRet ? 
'Y-m-d H:i:s' : 
oxRegistry::getLang()->translateString(
'fullDateFormat');
 
   62             $sFormat = $blForceEnglishRet ? 
'Y-m-d' : 
oxRegistry::getLang()->translateString(
'simpleDateFormat');
 
   65         if (count($aDate) != 3) {
 
   66             return date($sFormat);
 
   68             return $this->
_processDate($aTime, $aDate, $oStr->strstr($sDate, 
'.'), $sFormat);
 
   83         $sDate = $oObject->value;
 
  104             return $oObject->value;
 
  107         $blDefDateFound = 
false;
 
  111         foreach (array_keys($aDefDatePatterns) as $sDefDatePattern) {
 
  112             if ($oStr->preg_match($sDefDatePattern, $sDate)) {
 
  113                 $blDefDateFound = 
true;
 
  119         if ($blDefDateFound) {
 
  122             return $oObject->value;
 
  125         $blDateFound = 
false;
 
  126         $blTimeFound = 
false;
 
  127         $aDateMatches = array();
 
  128         $aTimeMatches = array();
 
  131         foreach ($aDatePatterns as $sPattern => $sType) {
 
  132             if ($oStr->preg_match($sPattern, $sDate, $aDateMatches)) {
 
  136                 $sDateFormat = $aDFormats[$sLocalDateFormat][0];
 
  137                 $aDFields = $aDFormats[$sType][1];
 
  148             $this->
_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
 
  150             return $oObject->value;
 
  154         foreach ($aTimePatterns as $sPattern => $sType) {
 
  155             if ($oStr->preg_match($sPattern, $sDate, $aTimeMatches)) {
 
  159                 $sTimeFormat = $aTFormats[$sLocalTimeFormat][0];
 
  160                 $aTFields = $aTFormats[$sType][1];
 
  163                 if ($sType == 
"USA" && isset($aTimeMatches[4])) {
 
  164                     $iIntVal = (int) $aTimeMatches[1];
 
  165                     if ($aTimeMatches[4] == 
"PM") {
 
  169                     } elseif ($aTimeMatches[4] == 
"AM" && $aTimeMatches[1] == 
"12") {
 
  173                     $aTimeMatches[1] = sprintf(
"%02d", $iIntVal);
 
  183             $this->
_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
 
  185             return $oObject->value;
 
  188         $this->
_formatCorrectTimeValue($oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields);
 
  191         if (!$oObject->fldmax_length) {
 
  195         return $oObject->value;
 
  210         $sSQLTimeStampPattern = 
"/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$/";
 
  211         $sISOTimeStampPattern = 
"/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/";
 
  216         if ($blToTimeStamp) {
 
  220             if ($oStr->preg_match($sISOTimeStampPattern, $oObject->value, $aMatches)) {
 
  222                 $oObject->setValue($aMatches[1] . $aMatches[2] . $aMatches[3] . $aMatches[4] . $aMatches[5] . $aMatches[6]);
 
  223                 $oObject->fldmax_length = strlen($oObject->value);
 
  225                 return $oObject->value;
 
  231             if ($oStr->preg_match($sSQLTimeStampPattern, $oObject->value, $aMatches)) {
 
  232                 $iTimestamp = mktime(
 
  244                 $oObject->setValue(trim(date(
"Y-m-d H:i:s", $iTimestamp)));
 
  245                 $oObject->fldmax_length = strlen($oObject->value);
 
  248                 return $oObject->value;
 
  284         foreach (array_keys($aDefTimePatterns) as $sDefTimePattern) {
 
  285             if ($oStr->preg_match($sDefTimePattern, $sDate)) {
 
  286                 $blDefTimeFound = 
true;
 
  293             $oObject->setValue(trim($aDFormats[$sLocalDateFormat][2])); 
 
  295             $oObject->fldmax_length = strlen($oObject->value);
 
  298         } elseif ($blDefTimeFound) {
 
  300             $oObject->setValue(trim($aDFormats[$sLocalDateFormat][2] . 
" " . $aTFormats[$sLocalTimeFormat][2]));
 
  302             $oObject->fldmax_length = strlen($oObject->value);
 
  320         if (!$sLocalTimeFormat || $blToTimeStamp) {
 
  321             $sLocalTimeFormat = 
"ISO";
 
  324         return $sLocalTimeFormat;
 
  339         if (!$sLocalDateFormat || $blToTimeStamp) {
 
  340             $sLocalDateFormat = 
"ISO";
 
  343         return $sLocalDateFormat;
 
  354         $aDefDatePatterns = array(
"/^0000-00-00/"   => 
"ISO",
 
  355                                   "/^00\.00\.0000/" => 
"EUR",
 
  356                                   "/^00\/00\/0000/" => 
"USA" 
  359         return $aDefDatePatterns;
 
  370         $aDefTimePatterns = array(
"/00:00:00$/"    => 
"ISO",
 
  371                                   "/00\.00\.00$/"  => 
"EUR",
 
  372                                   "/00:00:00 AM$/" => 
"USA" 
  375         return $aDefTimePatterns;
 
  386         $aDatePatterns = array(
"/^([0-9]{4})-([0-9]{2})-([0-9]{2})/"   => 
"ISO",
 
  387                                "/^([0-9]{2})\.([0-9]{2})\.([0-9]{4})/" => 
"EUR",
 
  388                                "/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})/" => 
"USA" 
  391         return $aDatePatterns;
 
  402         $aTimePatterns = array(
"/([0-9]{2}):([0-9]{2}):([0-9]{2})$/"                 => 
"ISO",
 
  403                                "/([0-9]{2})\.([0-9]{2})\.([0-9]{2})$/"               => 
"EUR",
 
  404                                "/([0-9]{2}):([0-9]{2}):([0-9]{2}) ([AP]{1}[M]{1})$/" => 
"USA" 
  407         return $aTimePatterns;
 
  418         $aDFormats = array(
"ISO" => array(
"Y-m-d", array(2, 3, 1), 
"0000-00-00"),
 
  419                            "EUR" => array(
"d.m.Y", array(2, 1, 3), 
"00.00.0000"),
 
  420                            "USA" => array(
"m/d/Y", array(1, 2, 3), 
"00/00/0000")
 
  434         $aTFormats = array(
"ISO" => array(
"H:i:s", array(1, 2, 3), 
"00:00:00"),
 
  435                            "EUR" => array(
"H.i.s", array(1, 2, 3), 
"00.00.00"),
 
  436                            "USA" => array(
"h:i:s A", array(1, 2, 3), 
"00:00:00 AM")
 
  455         $sReturn = $aDFormats[$sLocalDateFormat][2];
 
  457             $sReturn .= 
" " . $aTFormats[$sLocalTimeFormat][2];
 
  460         if ($oObject instanceof 
oxField) {
 
  461             $oObject->setValue(trim($sReturn));
 
  463             $oObject->value = trim($sReturn);
 
  466         $oObject->fldmax_length = strlen($oObject->value);
 
  477     protected function _setDate($oObject, $sDateFormat, $aDFields, $aDateMatches)
 
  480         $iTimestamp = mktime(
 
  481             0, 0, 0, $aDateMatches[$aDFields[0]],
 
  482             $aDateMatches[$aDFields[1]],
 
  483             $aDateMatches[$aDFields[2]]
 
  486         if ($oObject instanceof 
oxField) {
 
  487             $oObject->setValue(@date($sDateFormat, $iTimestamp));
 
  489             $oObject->value = @date($sDateFormat, $iTimestamp);
 
  492         $oObject->fldmax_length = strlen($oObject->value);
 
  506     protected function _formatCorrectTimeValue($oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields)
 
  509         $iTimestamp = @mktime(
 
  510             (
int) $aTimeMatches[$aTFields[0]],
 
  511             (
int) $aTimeMatches[$aTFields[1]],
 
  512             (
int) $aTimeMatches[$aTFields[2]],
 
  513             (
int) $aDateMatches[$aDFields[0]],
 
  514             (
int) $aDateMatches[$aDFields[1]],
 
  515             (
int) $aDateMatches[$aDFields[2]]
 
  518         if ($oObject instanceof 
oxField) {
 
  519             $oObject->setValue(trim(@date($sDateFormat . 
" " . $sTimeFormat, $iTimestamp)));
 
  521             $oObject->value = trim(@date($sDateFormat . 
" " . $sTimeFormat, $iTimestamp));
 
  525         $oObject->fldmax_length = strlen($oObject->value);
 
  547     public function formTime($sTime = 
'now', $sTime2 = null)
 
  549         $oDate = 
new DateTime($sTime);
 
  552             $aHourToCheck = explode(
':', $sTime2);
 
  553             $iHour = $aHourToCheck[0];
 
  554             $iMinutes = $aHourToCheck[1];
 
  555             $iSecond = $aHourToCheck[2];
 
  556             $oDate->setTime($iHour, $iMinutes, $iSecond);
 
  571         $iServerTimeShift = $this->
getConfig()->getConfigParam(
'iServerTimeShift');
 
  572         if ($iServerTimeShift) {
 
  573             $iTime = $iTime + ((int) $iServerTimeShift * 3600);
 
  589     public function getWeekNumber($iFirstWeekDay, $sTimestamp = null, $sFormat = null)
 
  591         if ($sTimestamp == null) {
 
  592             $sTimestamp = time();
 
  594         if ($sFormat == null) {
 
  596             if ($iFirstWeekDay) {
 
  601         return (
int) strftime($sFormat, $sTimestamp);
 
  613         $aDate = explode(
".", $sDate);
 
  615         if (isset($aDate) && count($aDate) > 1) {
 
  616             if (count($aDate) == 2) {
 
  617                 $sDate = $aDate[1] . 
"-" . $aDate[0];
 
  619                 $sDate = $aDate[2] . 
"-" . $aDate[1] . 
"-" . $aDate[0];
 
  638         if (!empty($sDate)) {
 
  639             $sDate = preg_replace(
"/[^0-9a-z]/i", 
"", $sDate);
 
  640             if (is_numeric($sDate) && $sDate == 0) {
 
  663             return date($sFormat, mktime($aTime[0], $aTime[1], $aTime[2], $aDate[1], $aDate[0], $aDate[2]));
 
  665             return date($sFormat, mktime($aTime[0], $aTime[1], $aTime[2], $aDate[1], $aDate[2], $aDate[0]));