35 public function formatDBDate( $sDBDateIn, $blForceEnglishRet =
false )
43 if ( $blForceEnglishRet && $oStr->strstr( $sDBDateIn,
'-' ) ) {
47 if ( $this->
isEmptyDate( $sDBDateIn ) && $sDBDateIn !=
'-' ) {
49 } elseif ( $sDBDateIn ==
'-' ) {
50 return '0000-00-00 00:00:00';
54 if ( is_numeric( $sDBDateIn ) ) {
56 $sNew = substr( $sDBDateIn, 0, 4 ).
'-'.substr( $sDBDateIn, 4, 2 ).
'-'.substr( $sDBDateIn, 6, 2 ).
' ';
58 if ( strlen($sDBDateIn) > 8 ) {
59 $sNew .= substr( $sDBDateIn, 8, 2 ).
':'.substr( $sDBDateIn, 10, 2 ).
':'.substr( $sDBDateIn, 12, 2 );
66 $aData = explode(
' ', trim( $sDBDateIn ) );
69 $sTime = ( isset( $aData[1] ) && $oStr->strstr( $aData[1],
':' ) )?$aData[1]:
'';
70 $aTime = $sTime?explode(
':', $sTime ):array( 0, 0, 0 );
73 $sDate = isset( $aData[0] )?$aData[0]:
'';
74 $aDate = preg_split(
'/[\/.-]/', $sDate );
78 $sFormat = $blForceEnglishRet ?
'Y-m-d H:i:s' :
oxRegistry::getLang()->translateString(
'fullDateFormat' );
80 $sFormat = $blForceEnglishRet ?
'Y-m-d' :
oxRegistry::getLang()->translateString(
'simpleDateFormat' );
83 if ( count( $aDate ) != 3 ) {
84 return date( $sFormat );
86 return $this->
_processDate( $aTime, $aDate, $oStr->strstr( $sDate,
'.' ), $sFormat );
101 $sDate = $oObject->value;
121 return $oObject->value;
124 $blDefDateFound =
false;
128 foreach ( array_keys( $aDefDatePatterns ) as $sDefDatePattern ) {
129 if ( $oStr->preg_match( $sDefDatePattern, $sDate)) {
130 $blDefDateFound =
true;
136 if ( $blDefDateFound) {
138 return $oObject->value;
141 $blDateFound =
false;
142 $blTimeFound =
false;
143 $aDateMatches = array();
144 $aTimeMatches = array();
147 foreach ( $aDatePatterns as $sPattern => $sType) {
148 if ( $oStr->preg_match( $sPattern, $sDate, $aDateMatches)) {
152 $sDateFormat = $aDFormats[$sLocalDateFormat][0];
153 $aDFields = $aDFormats[$sType][1];
159 if ( !$blDateFound) {
164 $this->
_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
165 return $oObject->value;
169 foreach ( $aTimePatterns as $sPattern => $sType) {
170 if ( $oStr->preg_match( $sPattern, $sDate, $aTimeMatches)) {
174 $sTimeFormat = $aTFormats[$sLocalTimeFormat][0];
175 $aTFields = $aTFormats[$sType][1];
178 if ( $sType ==
"USA" && isset($aTimeMatches[4])) {
179 $iIntVal = (int) $aTimeMatches[1];
180 if ( $aTimeMatches[4] ==
"PM") {
181 if ( $iIntVal < 13) {
184 } elseif ( $aTimeMatches[4] ==
"AM" && $aTimeMatches[1] ==
"12") {
188 $aTimeMatches[1] = sprintf(
"%02d", $iIntVal);
195 if ( !$blTimeFound) {
198 $this->
_setDate($oObject, $sDateFormat, $aDFields, $aDateMatches);
199 return $oObject->value;
202 $this->
_formatCorrectTimeValue($oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields);
205 if ( !$oObject->fldmax_length) {
208 return $oObject->value;
222 $sSQLTimeStampPattern =
"/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$/";
223 $sISOTimeStampPattern =
"/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/";
228 if ( $blToTimeStamp) {
232 if ( $oStr->preg_match( $sISOTimeStampPattern, $oObject->value, $aMatches)) {
234 $oObject->setValue($aMatches[1].$aMatches[2].$aMatches[3].$aMatches[4].$aMatches[5].$aMatches[6]);
235 $oObject->fldmax_length = strlen( $oObject->value);
236 return $oObject->value;
242 if ( $oStr->preg_match( $sSQLTimeStampPattern, $oObject->value, $aMatches ) ) {
243 $iTimestamp = mktime( $aMatches[4],
249 if ( !$iTimestamp ) {
253 $oObject->setValue(trim( date(
"Y-m-d H:i:s", $iTimestamp)));
254 $oObject->fldmax_length = strlen( $oObject->value);
256 return $oObject->value;
292 foreach ( array_keys( $aDefTimePatterns ) as $sDefTimePattern ) {
293 if ( $oStr->preg_match( $sDefTimePattern, $sDate ) ) {
294 $blDefTimeFound =
true;
301 $oObject->setValue(trim( $aDFormats[$sLocalDateFormat][2] ));
303 $oObject->fldmax_length = strlen( $oObject->value );
305 } elseif ( $blDefTimeFound ) {
307 $oObject->setValue(trim( $aDFormats[$sLocalDateFormat][2] .
" " . $aTFormats[$sLocalTimeFormat][2] ));
309 $oObject->fldmax_length = strlen( $oObject->value );
326 if ( !$sLocalTimeFormat || $blToTimeStamp) {
327 $sLocalTimeFormat =
"ISO";
329 return $sLocalTimeFormat;
344 if ( !$sLocalDateFormat || $blToTimeStamp) {
345 $sLocalDateFormat =
"ISO";
347 return $sLocalDateFormat;
358 $aDefDatePatterns = array(
"/^0000-00-00/" =>
"ISO",
359 "/^00\.00\.0000/" =>
"EUR",
360 "/^00\/00\/0000/" =>
"USA"
362 return $aDefDatePatterns;
373 $aDefTimePatterns = array(
"/00:00:00$/" =>
"ISO",
374 "/00\.00\.00$/" =>
"EUR",
375 "/00:00:00 AM$/" =>
"USA"
377 return $aDefTimePatterns;
388 $aDatePatterns = array(
"/^([0-9]{4})-([0-9]{2})-([0-9]{2})/" =>
"ISO",
389 "/^([0-9]{2})\.([0-9]{2})\.([0-9]{4})/" =>
"EUR",
390 "/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})/" =>
"USA"
392 return $aDatePatterns;
403 $aTimePatterns = array(
"/([0-9]{2}):([0-9]{2}):([0-9]{2})$/" =>
"ISO",
404 "/([0-9]{2})\.([0-9]{2})\.([0-9]{2})$/" =>
"EUR",
405 "/([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")
433 $aTFormats = array(
"ISO" => array(
"H:i:s", array(1, 2, 3 ),
"00:00:00"),
434 "EUR" => array(
"H.i.s", array(1, 2, 3 ),
"00.00.00"),
435 "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);
479 protected function _setDate( $oObject, $sDateFormat, $aDFields, $aDateMatches )
482 $iTimestamp = mktime( 0, 0, 0, $aDateMatches[$aDFields[0]],
483 $aDateMatches[$aDFields[1]],
484 $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 );
508 protected function _formatCorrectTimeValue( $oObject, $sDateFormat, $sTimeFormat, $aDateMatches, $aTimeMatches, $aTFields, $aDFields )
511 $iTimestamp = @mktime( (
int) $aTimeMatches[$aTFields[0]],
512 (
int) $aTimeMatches[$aTFields[1]],
513 (
int) $aTimeMatches[$aTFields[2]],
514 (
int) $aDateMatches[$aDFields[0]],
515 (
int) $aDateMatches[$aDFields[1]],
516 (
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 );
536 $iServerTimeShift = $this->
getConfig()->getConfigParam(
'iServerTimeShift' );
537 if ( !$iServerTimeShift ) {
541 return ( time() + ( (
int) $iServerTimeShift * 3600 ) );
555 public function getWeekNumber( $iFirstWeekDay, $sTimestamp = null, $sFormat = null )
557 if ( $sTimestamp == null ) {
558 $sTimestamp = time();
560 if ( $sFormat == null ) {
562 if ( $iFirstWeekDay ) {
566 return (
int) strftime( $sFormat, $sTimestamp );
578 $aDate = explode(
".", $sDate);
580 if ( isset( $aDate ) && count( $aDate) > 1) {
581 if ( count( $aDate) == 2) {
582 $sDate = $aDate[1].
"-".$aDate[0];
584 $sDate = $aDate[2].
"-".$aDate[1].
"-".$aDate[0];
604 return date( $sFormat, mktime( $aTime[0], $aTime[1], $aTime[2], $aDate[1], $aDate[0], $aDate[2] ) );
606 return date( $sFormat, mktime( $aTime[0], $aTime[1], $aTime[2], $aDate[1], $aDate[2], $aDate[0] ) );
622 if ( !empty( $sDate ) ) {
623 $sDate = preg_replace(
"/[^0-9a-z]/i",
"", $sDate);
624 if ( is_numeric( $sDate ) && $sDate == 0 ) {