00001 <?php
00097 class SMWTimeValue extends SMWDataValue {
00098
00099 protected $m_dataitem_greg = null;
00100 protected $m_dataitem_jul = null;
00101
00102 protected $m_wikivalue;
00103
00104
00105 protected static $m_months = array( 'January', 'February', 'March', 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' );
00106 protected static $m_monthsshort = array( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );
00107 protected static $m_formats = array( SMW_Y => array( 'y' ), SMW_YM => array( 'y', 'm' ), SMW_MY => array( 'm', 'y' ), SMW_YDM => array( 'y', 'd', 'm' ), SMW_YMD => array( 'y', 'm', 'd' ), SMW_DMY => array( 'd', 'm', 'y' ), SMW_MDY => array( 'm', 'd', 'y' ) );
00108
00110 protected static $m_tz = array( 'A' => 1, 'ACDT' => 10.5, 'ACST' => 9.5, 'ADT' => -3, 'AEDT' => 11,
00111 'AEST' => 10, 'AKDT' => -8, 'AKST' => -9, 'AST' => -4, 'AWDT' => 9, 'AWST' => 8,
00112 'B' => 2, 'BST' => 1, 'C' => 3, 'CDT' => - 5, 'CEDT' => 2, 'CEST' => 2,
00113 'CET' => 1, 'CST' => -6, 'CXT' => 7, 'D' => 4, 'E' => 5, 'EDT' => - 4,
00114 'EEDT' => 3, 'EEST' => 3, 'EET' => 2, 'EST' => - 5, 'F' => 6, 'G' => 7,
00115 'GMT' => 0, 'H' => 8, 'HAA' => - 3, 'HAC' => - 5, 'HADT' => - 9, 'HAE' => -4,
00116 'HAP' => -7, 'HAR' => -6, 'HAST' => -10, 'HAT' => -2.5, 'HAY' => -8,
00117 'HNA' => -4, 'HNC' => -6, 'HNE' => -5, 'HNP' => -8, 'HNR' => -7, 'HNT' => -3.5,
00118 'HNY' => -9, 'I' => 9, 'IST' => 1, 'K' => 10, 'L' => 11, 'M' => 12,
00119 'MDT' => -6, 'MESZ' => 2, 'MEZ' => 1, 'MSD' => 4, 'MSK' => 3, 'MST' => -7,
00120 'N' => -1, 'NDT' => -2.5, 'NFT' => 11.5, 'NST' => -3.5, 'O' => -2, 'P' => -3 ,
00121 'PDT' => -7, 'PST' => -8, 'Q' => - 4, 'R' => - 5, 'S' => -6, 'T' => -7,
00122 'U' => -8, 'UTC' => 0, 'V' => - 9, 'W' => -10, 'WDT' => 9, 'WEDT' => 1,
00123 'WEST' => 1, 'WET' => 0, 'WST' => 8, 'X' => -11, 'Y' => -12, 'Z' => 0 );
00125 protected static $m_miltz = array( 'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6,
00126 'G' => 7, 'H' => 8, 'I' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => -1, 'O' => -2,
00127 'P' => -3, 'Q' => -4, 'R' => -5, 'S' => -6, 'T' => -7, 'U' => -8, 'V' => -9,
00128 'W' => -10, 'X' => -11, 'Y' => -12, 'Z' => 0 );
00129
00131 const J1582 = 2299160.5;
00133 const MJD_EPOCH = 2400000.5;
00135 const PREHISTORY = -10000;
00136
00137 protected function parseUserValue( $value ) {
00138 $value = trim( $value );
00139 $this->m_wikivalue = $value;
00140 if ( $this->m_caption === false ) {
00141 $this->m_caption = $value;
00142 }
00143 $this->m_dataitem = null;
00144
00146 $datecomponents = array();
00147 $calendarmodel = $era = $hours = $minutes = $seconds = $timeoffset = false;
00148
00149
00150 if ( strlen( $value ) != 4 && wfTimestamp( TS_MW, $value ) !== false ) {
00151 $timeStamp = wfTimestamp( TS_MW, $value );
00152
00153 $this->m_dataitem = new SMWDITime(
00154 SMWDITime::CM_GREGORIAN,
00155 substr( $timeStamp, 0, 4 ),
00156 substr( $timeStamp, 4, 2 ),
00157 substr( $timeStamp, 6, 2 ),
00158 substr( $timeStamp, 8, 2 ),
00159 substr( $timeStamp, 10, 2 ),
00160 substr( $timeStamp, 12, 2 )
00161 );
00162 }
00163 elseif ( $this->parseDateString( $value, $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset ) ) {
00164 if ( ( $calendarmodel === false ) && ( $era === false ) && ( count( $datecomponents ) == 1 ) && ( intval( end( $datecomponents ) ) >= 100000 ) ) {
00165 $calendarmodel = 'JD';
00166 }
00167
00168 if ( ( $calendarmodel == 'JD' ) || ( $calendarmodel == 'MJD' ) ) {
00169 if ( ( $era === false ) && ( $hours === false ) && ( $timeoffset == 0 ) ) {
00170 try {
00171 $jd = floatval( reset( $datecomponents ) );
00172 if ( $calendarmodel == 'MJD' ) $jd += self::MJD_EPOCH;
00173 $this->m_dataitem = SMWDITime::newFromJD( $jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT, $this->m_typeid );
00174 } catch ( SMWDataItemException $e ) {
00175 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00176 }
00177 } else {
00178 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00179 }
00180 } else {
00181 $this->setDateFromParsedValues( $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset );
00182 }
00183 }
00184
00185 if ( is_null( $this->m_dataitem ) ) {
00186 $this->m_dataitem = new SMWDITime( SMWDITime::CM_GREGORIAN, 32202 );
00187 }
00188 }
00189
00206 protected function parseDateString( $string, &$datecomponents, &$calendarmodel, &$era, &$hours, &$minutes, &$seconds, &$timeoffset ) {
00207
00208
00209
00210
00211 $parsevalue = str_replace( array( '/', '.', ' ', ',' ), array( '-', ' ', ' ', ' ' ), $string );
00212
00213 $matches = preg_split( "/([T]?[0-2]?[0-9]:[\:0-9]+[+\-]?[0-2]?[0-9\:]+|[a-z,A-Z]+|[0-9]+|[ ])/u", $parsevalue , -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
00214 $datecomponents = array();
00215 $calendarmodel = $timezoneoffset = $era = $ampm = false;
00216 $hours = $minutes = $seconds = $timeoffset = false;
00217 $unclearparts = array();
00218 $matchisnumber = false;
00219 $matchisdate = false;
00220
00221 foreach ( $matches as $match ) {
00222 $prevmatchwasnumber = $matchisnumber;
00223 $prevmatchwasdate = $matchisdate;
00224 $matchisnumber = $matchisdate = false;
00225
00226 if ( $match == ' ' ) {
00227 $matchisdate = $prevmatchwasdate;
00228 } elseif ( $match == '-' ) {
00229 $datecomponents[] = $match;
00230 $matchisdate = true;
00231 } elseif ( is_numeric( $match ) &&
00232 ( $prevmatchwasdate || count( $datecomponents ) == 0 ) ) {
00233 $datecomponents[] = $match;
00234 $matchisnumber = true;
00235 $matchisdate = true;
00236 } elseif ( $era === false && in_array( $match, array( 'AD', 'CE' ) ) ) {
00237 $era = '+';
00238 } elseif ( $era === false && in_array( $match, array( 'BC', 'BCE' ) ) ) {
00239 $era = '-';
00240 } elseif ( $calendarmodel === false && in_array( $match, array( 'Gr', 'He', 'Jl', 'MJD', 'JD', 'OS' ) ) ) {
00241 $calendarmodel = $match;
00242 } elseif ( $ampm === false && ( strtolower( $match ) === 'am' || strtolower( $match ) === 'pm' ) ) {
00243 $ampm = strtolower( $match );
00244 } elseif ( $hours === false && self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) {
00245
00246 } elseif ( $hours !== false && $timezoneoffset === false &&
00247 array_key_exists( $match, self::$m_tz ) ) {
00248
00249 $timezoneoffset = self::$m_tz[ $match ];
00250 } elseif ( $prevmatchwasnumber && $hours === false && $timezoneoffset === false &&
00251 array_key_exists( $match, self::$m_miltz ) &&
00252 self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) {
00253
00254 array_pop( $datecomponents );
00255 $timezoneoffset = self::$m_miltz[ $match ];
00256 } elseif ( ( $prevmatchwasdate || count( $datecomponents ) == 0 ) &&
00257 $this->parseMonthString( $match, $monthname ) ) {
00258 $datecomponents[] = $monthname;
00259 $matchisdate = true;
00260 } elseif ( $prevmatchwasnumber && $prevmatchwasdate && in_array( $match, array( 'st', 'nd', 'rd', 'th' ) ) ) {
00261 $datecomponents[] = 'd' . strval( array_pop( $datecomponents ) );
00262 $matchisdate = true;
00263 } else {
00264 $unclearparts[] = $match;
00265 }
00266 }
00267
00268
00269
00270
00271
00272
00273
00274 if ( count( $unclearparts ) != 0 ||
00275 ( $timezoneoffset !== false && $timeoffset !== false ) ) {
00276 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00277 return false;
00278 }
00279
00280 $timeoffset = $timeoffset + $timezoneoffset;
00281
00282
00283 if ( $ampm !== false && ( $hours > 12 || $hours == 0 ) ) {
00284 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00285 return false;
00286 } elseif ( $ampm == 'am' && $hours == 12 ) {
00287 $hours = 0;
00288 } elseif ( $ampm == 'pm' && $hours < 12 ) {
00289 $hours += 12;
00290 }
00291
00292 return true;
00293 }
00294
00309 public static function parseTimeString( $string, &$hours, &$minutes, &$seconds, &$timeoffset ) {
00310 if ( !preg_match( "/^[T]?([0-2]?[0-9]):([0-5][0-9])(:[0-5][0-9])?(([+\-][0-2]?[0-9])(:(30|00))?)?$/u", $string, $match ) ) {
00311 return false;
00312 } else {
00313 $nhours = intval( $match[1] );
00314 $nminutes = $match[2] ? intval( $match[2] ) : false;
00315 if ( ( count( $match ) > 3 ) && ( $match[3] !== '' ) ) {
00316 $nseconds = intval( substr( $match[3], 1 ) );
00317 } else {
00318 $nseconds = false;
00319 }
00320 if ( ( $nhours < 25 ) && ( ( $nhours < 24 ) || ( $nminutes + $nseconds == 0 ) ) ) {
00321 $hours = $nhours;
00322 $minutes = $nminutes;
00323 $seconds = $nseconds;
00324 if ( ( count( $match ) > 5 ) && ( $match[5] !== '' ) ) {
00325 $timeoffset = intval( $match[5] );
00326 if ( ( count( $match ) > 7 ) && ( $match[7] == '30' ) ) {
00327 $timeoffset += 0.5;
00328 }
00329 } else {
00330 $timeoffset = false;
00331 }
00332 return true;
00333 } else {
00334 return false;
00335 }
00336 }
00337 }
00338
00350 protected static function parseMilTimeString( $string, &$hours, &$minutes, &$seconds ) {
00351 if ( !preg_match( "/^([0-2][0-9])([0-5][0-9])([0-5][0-9])?$/u", $string, $match ) ) {
00352 return false;
00353 } else {
00354 $nhours = intval( $match[1] );
00355 $nminutes = $match[2] ? intval( $match[2] ) : false;
00356 $nseconds = ( ( count( $match ) > 3 ) && $match[3] ) ? intval( $match[3] ) : false;
00357 if ( ( $nhours < 25 ) && ( ( $nhours < 24 ) || ( $nminutes + $nseconds == 0 ) ) ) {
00358 $hours = $nhours;
00359 $minutes = $nminutes;
00360 $seconds = $nseconds;
00361 return true;
00362 } else {
00363 return false;
00364 }
00365 }
00366 }
00367
00377 protected static function parseMonthString( $string, &$monthname ) {
00378 global $smwgContLang;
00379 $monthnum = $smwgContLang->findMonth( $string );
00380 if ( $monthnum !== false ) {
00381 $monthnum -= 1;
00382 } else {
00383 $monthnum = array_search( $string, self::$m_months );
00384 }
00385 if ( $monthnum !== false ) {
00386 $monthname = self::$m_monthsshort[ $monthnum ];
00387 return true;
00388 } elseif ( array_search( $string, self::$m_monthsshort ) !== false ) {
00389 $monthname = $string;
00390 return true;
00391 } else {
00392 return false;
00393 }
00394 }
00395
00409 protected function interpretDateComponents( $datecomponents, &$date ) {
00410 global $smwgContLang;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 $datevector = 1;
00423 $propercomponents = array();
00424 $justfounddash = true;
00425 $error = false;
00426 $numvalue = 0;
00427 foreach ( $datecomponents as $component ) {
00428 if ( $component == "-" ) {
00429 if ( $justfounddash ) {
00430 $error = true;
00431 break;
00432 }
00433 $justfounddash = true;
00434 } else {
00435 $justfounddash = false;
00436 $datevector = ( $datevector << 3 ) | $this->checkDateComponent( $component, $numvalue );
00437 $propercomponents[] = $numvalue;
00438 }
00439 }
00440 if ( ( $error ) || ( $justfounddash ) || ( count( $propercomponents ) == 0 ) || ( count( $propercomponents ) > 3 ) ) {
00441 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00442 return false;
00443 }
00444
00445 $dateformats = $smwgContLang->getDateFormats();
00446 $date = array( 'y' => false, 'm' => false, 'd' => false );
00447 foreach ( $dateformats[count( $propercomponents ) - 1] as $formatvector ) {
00448 if ( !( ~$datevector & $formatvector ) ) {
00449 $i = 0;
00450 foreach ( self::$m_formats[$formatvector] as $fieldname ) {
00451 $date[$fieldname] = $propercomponents[$i];
00452 $i += 1;
00453 }
00454 break;
00455 }
00456 }
00457 if ( $date['y'] === false ) {
00458 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00459 return false;
00460 }
00461 return true;
00462 }
00463
00478 protected function setDateFromParsedValues( $datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset ) {
00479 $date = false;
00480 if ( !$this->interpretDateComponents( $datecomponents, $date ) ) {
00481 return false;
00482 }
00483
00484
00485 if ( ( $era == '-' ) && ( $date['y'] > 0 ) ) {
00486 $date['y'] = -( $date['y'] );
00487 }
00488
00489 if ( ( $calendarmodel == 'OS' ) &&
00490 ( ( $date['m'] < 3 ) || ( ( $date['m'] == 3 ) && ( $date['d'] < 25 ) ) ) ) {
00491 $date['y']++;
00492 }
00493
00494 $calmod = $this->getCalendarModel( $calendarmodel, $date['y'], $date['m'], $date['d'] );
00495 try {
00496 $this->m_dataitem = new SMWDITime( $calmod, $date['y'], $date['m'], $date['d'], $hours, $minutes, $seconds, $this->m_typeid );
00497 } catch ( SMWDataItemException $e ) {
00498 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00499 return false;
00500 }
00501
00502
00503
00504
00505 if ( ( $date['y'] <= self::PREHISTORY ) &&
00506 ( ( $this->m_dataitem->getPrecision() > SMWDITime::PREC_Y ) || ( $calendarmodel !== false ) ) ) {
00507 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00508 return false;
00509 }
00510 if ( $timeoffset != 0 ) {
00511 $newjd = $this->m_dataitem->getJD() - $timeoffset / 24;
00512 try {
00513 $this->m_dataitem = SMWDITime::newFromJD( $newjd, $calmod, $this->m_dataitem->getPrecision(), $this->m_typeid );
00514 } catch ( SMWDataItemException $e ) {
00515 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
00516 return false;
00517 }
00518 }
00519 return true;
00520 }
00521
00533 protected static function checkDateComponent( $component, &$numvalue ) {
00534 if ( $component === '' ) {
00535 $numvalue = 0;
00536 return 0;
00537 } elseif ( is_numeric( $component ) ) {
00538 $numvalue = intval( $component );
00539 if ( ( $numvalue >= 1 ) && ( $numvalue <= 12 ) ) {
00540 return SMW_DAY_MONTH_YEAR;
00541 } elseif ( ( $numvalue >= 1 ) && ( $numvalue <= 31 ) ) {
00542 return SMW_DAY_YEAR;
00543 } else {
00544 return SMW_YEAR;
00545 }
00546 } elseif ( $component { 0 } == 'd' ) {
00547 if ( is_numeric( substr( $component, 1 ) ) ) {
00548 $numvalue = intval( substr( $component, 1 ) );
00549 return ( ( $numvalue >= 1 ) && ( $numvalue <= 31 ) ) ? SMW_DAY : 0;
00550 } else {
00551 return 0;
00552 }
00553 } else {
00554 $monthnum = array_search( $component, self::$m_monthsshort );
00555 if ( $monthnum !== false ) {
00556 $numvalue = $monthnum + 1;
00557 return SMW_MONTH;
00558 } else {
00559 return 0;
00560 }
00561 }
00562 }
00563
00573 protected function getCalendarModel( $presetmodel, $year, $month, $day ) {
00574 if ( $presetmodel == 'OS' ) {
00575 $presetmodel = 'Jl';
00576 }
00577 if ( $presetmodel == 'Gr' ) {
00578 return SMWDITime::CM_GREGORIAN;
00579 } elseif ( $presetmodel == 'Jl' ) {
00580 return SMWDITime::CM_JULIAN;
00581 }
00582 if ( ( $year > 1582 ) ||
00583 ( ( $year == 1582 ) && ( $month > 10 ) ) ||
00584 ( ( $year == 1582 ) && ( $month == 10 ) && ( $day > 4 ) ) ) {
00585 return SMWDITime::CM_GREGORIAN;
00586 } elseif ( $year > self::PREHISTORY ) {
00587 return SMWDITime::CM_JULIAN;
00588 } else {
00589
00590
00591
00592 return SMWDITime::CM_GREGORIAN;
00593 }
00594 }
00595
00601 protected function loadDataItem( SMWDataItem $dataItem ) {
00602 if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) {
00603 $this->m_dataitem = $dataItem;
00604 $this->m_caption = $this->m_wikivalue = false;
00605 return true;
00606 } else {
00607 return false;
00608 }
00609 }
00610
00611 public function getShortWikiText( $linked = NULL ) {
00612 return ( $this->m_caption !== false ) ? $this->m_caption : $this->getPreferredCaption();
00613 }
00614
00615 public function getShortHTMLText( $linker = NULL ) {
00616 return $this->getShortWikiText( $linker );
00617 }
00618
00619 public function getLongWikiText( $linked = NULL ) {
00620 return $this->isValid() ? $this->getPreferredCaption() : $this->getErrorText();
00621 }
00622
00623 public function getLongHTMLText( $linker = NULL ) {
00624 return $this->getLongWikiText( $linker );
00625 }
00626
00628 public function getWikiValue() {
00629 return $this->m_wikivalue ? $this->m_wikivalue : $this->getPreferredCaption();
00630 }
00631
00632 public function isNumeric() {
00633 return true;
00634 }
00635
00644 public function getYear( $calendarmodel = SMWDITime::CM_GREGORIAN ) {
00645 $di = $this->getDataForCalendarModel( $calendarmodel );
00646 if ( !is_null( $di ) ) {
00647 return $di->getYear();
00648 } else {
00649 return false;
00650 }
00651 }
00652
00661 public function getMonth( $calendarmodel = SMWDITime::CM_GREGORIAN, $default = 1 ) {
00662 $di = $this->getDataForCalendarModel( $calendarmodel );
00663 if ( !is_null( $di ) ) {
00664 return ( $di->getPrecision() >= SMWDITime::PREC_YM ) ? $di->getMonth() : $default;
00665 } else {
00666 return false;
00667 }
00668 }
00669
00678 public function getDay( $calendarmodel = SMWDITime::CM_GREGORIAN, $default = 1 ) {
00679 $di = $this->getDataForCalendarModel( $calendarmodel );
00680 if ( !is_null( $di ) ) {
00681 return ( $di->getPrecision() >= SMWDITime::PREC_YMD ) ? $di->getDay() : $default;
00682 } else {
00683 return false;
00684 }
00685 }
00686
00695 public function getTimeString( $default = '00:00:00' ) {
00696 if ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMDT ) {
00697 return $default;
00698 } else {
00699 return sprintf( "%02d", $this->m_dataitem->getHour() ) . ':' .
00700 sprintf( "%02d", $this->m_dataitem->getMinute() ) . ':' .
00701 sprintf( "%02d", $this->m_dataitem->getSecond() );
00702 }
00703 }
00704
00708 public function getXMLSchemaDate( $mindefault = true ) {
00709 return $this->getISO8601Date( $mindefault );
00710 }
00711
00727 public function getISO8601Date( $mindefault = true ) {
00728 $result = ( $this->getYear() > 0 ) ? '' : '-';
00729 $monthnum = $this->getMonth( SMWDITime::CM_GREGORIAN, ( $mindefault ? 1 : 12 ) );
00730 $result .= str_pad( $this->getYear(), 4, "0", STR_PAD_LEFT ) .
00731 '-' . str_pad( $monthnum, 2, "0", STR_PAD_LEFT );
00732 if ( !$mindefault && ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMD ) ) {
00733 $maxday = SMWDITime::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN );
00734 $result .= '-' . str_pad( $this->getDay( SMWDITime::CM_GREGORIAN, $maxday ), 2, "0", STR_PAD_LEFT );
00735 } else {
00736 $result .= '-' . str_pad( $this->getDay(), 2, "0", STR_PAD_LEFT );
00737 }
00738 if ( $this->m_dataitem->getPrecision() == SMWDITime::PREC_YMDT ) {
00739 $result .= 'T' . $this->getTimeString( ( $mindefault ? '00:00:00' : '23:59:59' ) );
00740 }
00741 return $result;
00742 }
00743
00750 public function getMediaWikiDate() {
00751 global $wgContLang;
00752
00753 $dataitem = $this->m_dataitem;
00754 $precision = $dataitem->getPrecision();
00755
00756 $year = $this->getYear();
00757 if ( $year < 0 || $year > 9999 ) $year = '0000';
00758 $year = str_pad( $year, 4, "0", STR_PAD_LEFT );
00759
00760 if ( $precision <= SMWDITime::PREC_Y ) {
00761 return $wgContLang->formatNum( $year, true );
00762 }
00763
00764 $month = str_pad( $this->getMonth( SMWDITime::CM_GREGORIAN ), 2, "0", STR_PAD_LEFT );
00765 $day = str_pad( $this->getDay( SMWDITime::CM_GREGORIAN ), 2, "0", STR_PAD_LEFT );
00766
00767 if ( $precision <= SMWDITime::PREC_YMD ) {
00768 return $wgContLang->date( "$year$month$day" . '000000', false, false );
00769 }
00770
00771 $time = str_replace( ':', '', $this->getTimeString() );
00772 return $wgContLang->timeAndDate( "$year$month$day$time", false, false );
00773 }
00774
00784 protected function getDataForCalendarModel( $calendarmodel ) {
00785 if ( $this->m_dataitem->getYear() <= self::PREHISTORY ) {
00786 return ( $this->m_dataitem->getCalendarModel() == $calendarmodel ) ? $this->m_dataitem : null;
00787 } elseif ( $calendarmodel == SMWDITime::CM_GREGORIAN ) {
00788 if ( $this->m_dataitem_greg === null ) {
00789 $this->m_dataitem_greg = $this->m_dataitem->getForCalendarModel( SMWDITime::CM_GREGORIAN );
00790 }
00791 return $this->m_dataitem_greg;
00792 } else {
00793 if ( $this->m_dataitem_jul === null ) {
00794 $this->m_dataitem_jul = $this->m_dataitem->getForCalendarModel( SMWDITime::CM_JULIAN );
00795 }
00796 return $this->m_dataitem_jul;
00797 }
00798 }
00799
00811 public function getCaptionFromDataitem( SMWDITime $dataitem ) {
00812 global $smwgContLang;
00813 if ( $dataitem->getYear() > 0 ) {
00814 $cestring = '';
00815 $result = number_format( $dataitem->getYear(), 0, '.', '' ) . ( $cestring ? ( ' ' . $cestring ) : '' );
00816 } else {
00817 $bcestring = 'BC';
00818 $result = number_format( -( $dataitem->getYear() ), 0, '.', '' ) . ( $bcestring ? ( ' ' . $bcestring ) : '' );
00819 }
00820 if ( $dataitem->getPrecision() >= SMWDITime::PREC_YM ) {
00821 $result = $smwgContLang->getMonthLabel( $dataitem->getMonth() ) . " " . $result;
00822 }
00823 if ( $dataitem->getPrecision() >= SMWDITime::PREC_YMD ) {
00824 $result = $dataitem->getDay() . " " . $result;
00825 }
00826 if ( $dataitem->getPrecision() >= SMWDITime::PREC_YMDT ) {
00827 $result .= " " . $this->getTimeString();
00828 }
00829 return $result;
00830 }
00831
00838 protected function getPreferredCaption() {
00839 $year = $this->m_dataitem->getYear();
00840
00841 if ( strtoupper( $this->m_outformat ) === 'ISO' || $this->m_outformat == '-' ) {
00842 return $this->getISO8601Date();
00843 } elseif ( strtoupper( $this->m_outformat ) === 'MEDIAWIKI' ) {
00844 return $this->getMediaWikiDate();
00845 } elseif ( strtoupper( $this->m_outformat ) === 'SORTKEY' ) {
00846 return $this->m_dataitem->getSortKey();
00847 } else {
00848 if ( $year <= self::PREHISTORY ) {
00849 return $this->getCaptionFromDataitem( $this->m_dataitem );
00850 } elseif ( $this->m_dataitem->getJD() < self::J1582 ) {
00851 return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_JULIAN ) );
00852 } else {
00853 return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_GREGORIAN ) );
00854 }
00855 }
00856 }
00857
00858 }