2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2010-08-22 14:31:05 +00:00
|
|
|
/**
|
|
|
|
|
* Date formatter
|
|
|
|
|
*
|
2012-04-30 09:22:16 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-22 14:31:05 +00:00
|
|
|
* @file
|
2012-04-30 09:22:16 +00:00
|
|
|
* @ingroup Parser
|
2010-08-22 14:31:05 +00:00
|
|
|
*/
|
2007-03-28 14:16:43 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-04-04 05:22:37 +00:00
|
|
|
* Date formatter, recognises dates in plain text and formats them accoding to user preferences.
|
2004-09-02 23:28:24 +00:00
|
|
|
* @todo preferences, OutputPage
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Parser
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2012-06-01 09:52:57 +00:00
|
|
|
class DateFormatter {
|
2003-11-20 13:12:41 +00:00
|
|
|
var $mSource, $mTarget;
|
2004-06-08 23:56:09 +00:00
|
|
|
var $monthNames = '', $rxDM, $rxMD, $rxDMY, $rxYDM, $rxMDY, $rxYMD;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
var $regexes, $pDays, $pMonths, $pYears;
|
2006-07-26 07:15:39 +00:00
|
|
|
var $rules, $xMonths, $preferences;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2012-06-01 09:52:57 +00:00
|
|
|
protected $lang;
|
|
|
|
|
|
2006-07-14 17:02:49 +00:00
|
|
|
const ALL = -1;
|
|
|
|
|
const NONE = 0;
|
|
|
|
|
const MDY = 1;
|
|
|
|
|
const DMY = 2;
|
|
|
|
|
const YMD = 3;
|
|
|
|
|
const ISO1 = 4;
|
|
|
|
|
const LASTPREF = 4;
|
|
|
|
|
const ISO2 = 5;
|
|
|
|
|
const YDM = 6;
|
|
|
|
|
const DM = 7;
|
|
|
|
|
const MD = 8;
|
|
|
|
|
const LAST = 8;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
2012-06-01 09:52:57 +00:00
|
|
|
* @param $lang Language In which language to format the date
|
2004-09-03 16:51:45 +00:00
|
|
|
*/
|
2012-06-01 09:52:57 +00:00
|
|
|
function __construct( Language $lang ) {
|
|
|
|
|
$this->lang = $lang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
$this->monthNames = $this->getMonthRegex();
|
|
|
|
|
for ( $i=1; $i<=12; $i++ ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$this->xMonths[$this->lang->lc( $this->lang->getMonthName( $i ) )] = $i;
|
|
|
|
|
$this->xMonths[$this->lang->lc( $this->lang->getMonthAbbreviation( $i ) )] = $i;
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-29 12:08:48 +00:00
|
|
|
$this->regexTrail = '(?![a-z])/iu';
|
|
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
# Partial regular expressions
|
2009-03-10 01:07:47 +00:00
|
|
|
$this->prxDM = '\[\[(\d{1,2})[ _](' . $this->monthNames . ')\]\]';
|
|
|
|
|
$this->prxMD = '\[\[(' . $this->monthNames . ')[ _](\d{1,2})\]\]';
|
|
|
|
|
$this->prxY = '\[\[(\d{1,4}([ _]BC|))\]\]';
|
|
|
|
|
$this->prxISO1 = '\[\[(-?\d{4})]]-\[\[(\d{2})-(\d{2})\]\]';
|
|
|
|
|
$this->prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})\]\]';
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
# Real regular expressions
|
2009-06-02 12:39:14 +00:00
|
|
|
$this->regexes[self::DMY] = "/{$this->prxDM}(?: *, *| +){$this->prxY}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::YDM] = "/{$this->prxY}(?: *, *| +){$this->prxDM}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::MDY] = "/{$this->prxMD}(?: *, *| +){$this->prxY}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::YMD] = "/{$this->prxY}(?: *, *| +){$this->prxMD}{$this->regexTrail}";
|
2006-07-14 17:02:49 +00:00
|
|
|
$this->regexes[self::DM] = "/{$this->prxDM}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::MD] = "/{$this->prxMD}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::ISO1] = "/{$this->prxISO1}{$this->regexTrail}";
|
|
|
|
|
$this->regexes[self::ISO2] = "/{$this->prxISO2}{$this->regexTrail}";
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
# Extraction keys
|
|
|
|
|
# See the comments in replace() for the meaning of the letters
|
2006-07-14 17:02:49 +00:00
|
|
|
$this->keys[self::DMY] = 'jFY';
|
|
|
|
|
$this->keys[self::YDM] = 'Y jF';
|
|
|
|
|
$this->keys[self::MDY] = 'FjY';
|
|
|
|
|
$this->keys[self::YMD] = 'Y Fj';
|
|
|
|
|
$this->keys[self::DM] = 'jF';
|
|
|
|
|
$this->keys[self::MD] = 'Fj';
|
|
|
|
|
$this->keys[self::ISO1] = 'ymd'; # y means ISO year
|
|
|
|
|
$this->keys[self::ISO2] = 'ymd';
|
2003-11-20 13:12:41 +00:00
|
|
|
|
|
|
|
|
# Target date formats
|
2006-07-14 17:02:49 +00:00
|
|
|
$this->targets[self::DMY] = '[[F j|j F]] [[Y]]';
|
|
|
|
|
$this->targets[self::YDM] = '[[Y]], [[F j|j F]]';
|
|
|
|
|
$this->targets[self::MDY] = '[[F j]], [[Y]]';
|
|
|
|
|
$this->targets[self::YMD] = '[[Y]] [[F j]]';
|
|
|
|
|
$this->targets[self::DM] = '[[F j|j F]]';
|
|
|
|
|
$this->targets[self::MD] = '[[F j]]';
|
|
|
|
|
$this->targets[self::ISO1] = '[[Y|y]]-[[F j|m-d]]';
|
|
|
|
|
$this->targets[self::ISO2] = '[[y-m-d]]';
|
2003-11-20 13:12:41 +00:00
|
|
|
|
|
|
|
|
# Rules
|
|
|
|
|
# pref source target
|
2006-07-14 17:02:49 +00:00
|
|
|
$this->rules[self::DMY][self::MD] = self::DM;
|
|
|
|
|
$this->rules[self::ALL][self::MD] = self::MD;
|
|
|
|
|
$this->rules[self::MDY][self::DM] = self::MD;
|
|
|
|
|
$this->rules[self::ALL][self::DM] = self::DM;
|
|
|
|
|
$this->rules[self::NONE][self::ISO2] = self::ISO1;
|
2006-07-26 07:15:39 +00:00
|
|
|
|
|
|
|
|
$this->preferences = array(
|
|
|
|
|
'default' => self::NONE,
|
|
|
|
|
'dmy' => self::DMY,
|
|
|
|
|
'mdy' => self::MDY,
|
|
|
|
|
'ymd' => self::YMD,
|
|
|
|
|
'ISO 8601' => self::ISO1,
|
|
|
|
|
);
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-04-20 15:42:08 +00:00
|
|
|
/**
|
2009-01-23 20:13:39 +00:00
|
|
|
* Get a DateFormatter object
|
|
|
|
|
*
|
2012-06-01 09:52:57 +00:00
|
|
|
* @param $lang Language|string|null In which language to format the date
|
|
|
|
|
* Defaults to the site content language
|
2009-01-23 20:13:39 +00:00
|
|
|
* @return DateFormatter object
|
2005-04-20 15:42:08 +00:00
|
|
|
*/
|
2012-06-01 09:52:57 +00:00
|
|
|
public static function &getInstance( $lang = null ) {
|
|
|
|
|
global $wgMemc, $wgContLang;
|
2005-04-20 15:42:08 +00:00
|
|
|
static $dateFormatter = false;
|
2012-06-01 09:52:57 +00:00
|
|
|
$lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
|
|
|
|
|
$key = wfMemcKey( 'dateformatter', $lang->getCode() );
|
2005-04-20 15:42:08 +00:00
|
|
|
if ( !$dateFormatter ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$dateFormatter = $wgMemc->get( $key );
|
2005-04-20 15:42:08 +00:00
|
|
|
if ( !$dateFormatter ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$dateFormatter = new DateFormatter( $lang );
|
|
|
|
|
$wgMemc->set( $key, $dateFormatter, 3600 );
|
2005-04-20 15:42:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $dateFormatter;
|
2006-01-07 13:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
2009-01-23 20:13:39 +00:00
|
|
|
* @param $preference String: User preference
|
|
|
|
|
* @param $text String: Text to reformat
|
2010-06-09 14:57:59 +00:00
|
|
|
* @param $options Array: can contain 'linked' and/or 'match-whole'
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return mixed|String
|
2004-09-03 16:51:45 +00:00
|
|
|
*/
|
2009-03-10 05:19:05 +00:00
|
|
|
function reformat( $preference, $text, $options = array('linked') ) {
|
|
|
|
|
$linked = in_array( 'linked', $options );
|
|
|
|
|
$match_whole = in_array( 'match-whole', $options );
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2006-07-26 07:15:39 +00:00
|
|
|
if ( isset( $this->preferences[$preference] ) ) {
|
|
|
|
|
$preference = $this->preferences[$preference];
|
|
|
|
|
} else {
|
|
|
|
|
$preference = self::NONE;
|
|
|
|
|
}
|
2006-07-14 17:02:49 +00:00
|
|
|
for ( $i=1; $i<=self::LAST; $i++ ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
$this->mSource = $i;
|
2007-01-03 05:42:51 +00:00
|
|
|
if ( isset ( $this->rules[$preference][$i] ) ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
# Specific rules
|
|
|
|
|
$this->mTarget = $this->rules[$preference][$i];
|
2007-01-03 05:42:51 +00:00
|
|
|
} elseif ( isset ( $this->rules[self::ALL][$i] ) ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
# General rules
|
2006-07-14 17:02:49 +00:00
|
|
|
$this->mTarget = $this->rules[self::ALL][$i];
|
2003-11-20 13:12:41 +00:00
|
|
|
} elseif ( $preference ) {
|
|
|
|
|
# User preference
|
|
|
|
|
$this->mTarget = $preference;
|
|
|
|
|
} else {
|
|
|
|
|
# Default
|
|
|
|
|
$this->mTarget = $i;
|
|
|
|
|
}
|
2009-03-10 01:07:47 +00:00
|
|
|
$regex = $this->regexes[$i];
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
// Horrible hack
|
|
|
|
|
if (!$linked) {
|
|
|
|
|
$regex = str_replace( array( '\[\[', '\]\]' ), '', $regex );
|
|
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 05:19:05 +00:00
|
|
|
if ($match_whole) {
|
|
|
|
|
// Let's hope this works
|
|
|
|
|
$regex = preg_replace( '!^/!', '/^', $regex );
|
|
|
|
|
$regex = str_replace( $this->regexTrail,
|
|
|
|
|
'$'.$this->regexTrail, $regex );
|
|
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
// Another horrible hack
|
|
|
|
|
$this->mLinked = $linked;
|
|
|
|
|
$text = preg_replace_callback( $regex, array( &$this, 'replace' ), $text );
|
|
|
|
|
unset($this->mLinked);
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
|
|
|
|
* @param $matches
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2004-09-03 16:51:45 +00:00
|
|
|
*/
|
|
|
|
|
function replace( $matches ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
# Extract information from $matches
|
2009-03-10 01:07:47 +00:00
|
|
|
$linked = true;
|
|
|
|
|
if ( isset( $this->mLinked ) )
|
|
|
|
|
$linked = $this->mLinked;
|
|
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
$bits = array();
|
|
|
|
|
$key = $this->keys[$this->mSource];
|
|
|
|
|
for ( $p=0; $p < strlen($key); $p++ ) {
|
2011-04-17 07:59:58 +00:00
|
|
|
if ( $key[$p] != ' ' ) {
|
|
|
|
|
$bits[$key[$p]] = $matches[$p+1];
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
return $this->formatDate( $bits, $linked );
|
2009-03-09 23:51:58 +00:00
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $bits array
|
|
|
|
|
* @param $link bool
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2009-03-10 01:07:47 +00:00
|
|
|
function formatDate( $bits, $link = true ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
$format = $this->targets[$this->mTarget];
|
2009-03-10 01:07:47 +00:00
|
|
|
|
|
|
|
|
if (!$link) {
|
|
|
|
|
// strip piped links
|
|
|
|
|
$format = preg_replace( '/\[\[[^|]+\|([^\]]+)\]\]/', '$1', $format );
|
|
|
|
|
// strip remaining links
|
|
|
|
|
$format = str_replace( array( '[[', ']]' ), '', $format );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
# Construct new date
|
2004-06-08 23:56:09 +00:00
|
|
|
$text = '';
|
2003-11-20 13:12:41 +00:00
|
|
|
$fail = false;
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-09 23:51:58 +00:00
|
|
|
// Pre-generate y/Y stuff because we need the year for the <span> title.
|
2009-03-10 01:07:47 +00:00
|
|
|
if ( !isset( $bits['y'] ) && isset( $bits['Y'] ) )
|
2009-03-09 23:51:58 +00:00
|
|
|
$bits['y'] = $this->makeIsoYear( $bits['Y'] );
|
2009-03-10 01:07:47 +00:00
|
|
|
if ( !isset( $bits['Y'] ) && isset( $bits['y'] ) )
|
2009-03-09 23:51:58 +00:00
|
|
|
$bits['Y'] = $this->makeNormalYear( $bits['y'] );
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
if ( !isset( $bits['m'] ) ) {
|
|
|
|
|
$m = $this->makeIsoMonth( $bits['F'] );
|
|
|
|
|
if ( !$m || $m == '00' ) {
|
|
|
|
|
$fail = true;
|
|
|
|
|
} else {
|
|
|
|
|
$bits['m'] = $m;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
if ( !isset($bits['d']) ) {
|
|
|
|
|
$bits['d'] = sprintf( '%02d', $bits['j'] );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
for ( $p=0; $p < strlen( $format ); $p++ ) {
|
2011-04-17 07:59:58 +00:00
|
|
|
$char = $format[$p];
|
2003-11-20 13:12:41 +00:00
|
|
|
switch ( $char ) {
|
|
|
|
|
case 'd': # ISO day of month
|
2009-03-10 01:07:47 +00:00
|
|
|
$text .= $bits['d'];
|
2003-11-20 13:12:41 +00:00
|
|
|
break;
|
|
|
|
|
case 'm': # ISO month
|
2009-03-10 01:07:47 +00:00
|
|
|
$text .= $bits['m'];
|
2003-11-20 13:12:41 +00:00
|
|
|
break;
|
|
|
|
|
case 'y': # ISO year
|
2009-03-09 23:51:58 +00:00
|
|
|
$text .= $bits['y'];
|
2003-11-20 13:12:41 +00:00
|
|
|
break;
|
|
|
|
|
case 'j': # ordinary day of month
|
2004-12-29 03:27:16 +00:00
|
|
|
if ( !isset($bits['j']) ) {
|
2005-08-16 23:36:16 +00:00
|
|
|
$text .= intval( $bits['d'] );
|
2003-11-20 13:12:41 +00:00
|
|
|
} else {
|
|
|
|
|
$text .= $bits['j'];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'F': # long month
|
2004-12-29 03:27:16 +00:00
|
|
|
if ( !isset( $bits['F'] ) ) {
|
2005-08-16 23:36:16 +00:00
|
|
|
$m = intval($bits['m']);
|
2003-11-20 13:12:41 +00:00
|
|
|
if ( $m > 12 || $m < 1 ) {
|
|
|
|
|
$fail = true;
|
|
|
|
|
} else {
|
2012-06-01 09:52:57 +00:00
|
|
|
$text .= $this->lang->getMonthName( $m );
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$text .= ucfirst( $bits['F'] );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'Y': # ordinary (optional BC) year
|
2009-03-09 23:51:58 +00:00
|
|
|
$text .= $bits['Y'];
|
2003-11-20 13:12:41 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$text .= $char;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $fail ) {
|
|
|
|
|
$text = $matches[0];
|
|
|
|
|
}
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-10 01:07:47 +00:00
|
|
|
$isoBits = array();
|
|
|
|
|
if ( isset($bits['y']) )
|
|
|
|
|
$isoBits[] = $bits['y'];
|
|
|
|
|
$isoBits[] = $bits['m'];
|
|
|
|
|
$isoBits[] = $bits['d'];
|
2010-09-11 21:55:21 +00:00
|
|
|
$isoDate = implode( '-', $isoBits );
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2009-03-09 23:51:58 +00:00
|
|
|
// Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
|
2009-08-21 20:39:35 +00:00
|
|
|
$text = Html::rawElement( 'span',
|
2009-03-09 23:51:58 +00:00
|
|
|
array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text );
|
2012-06-01 09:52:57 +00:00
|
|
|
|
2003-11-20 13:12:41 +00:00
|
|
|
return $text;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2004-09-03 16:51:45 +00:00
|
|
|
*/
|
|
|
|
|
function getMonthRegex() {
|
2004-12-29 03:27:16 +00:00
|
|
|
$names = array();
|
|
|
|
|
for( $i = 1; $i <= 12; $i++ ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$names[] = $this->lang->getMonthName( $i );
|
|
|
|
|
$names[] = $this->lang->getMonthAbbreviation( $i );
|
2004-12-29 03:27:16 +00:00
|
|
|
}
|
|
|
|
|
return implode( '|', $names );
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
|
|
|
|
* Makes an ISO month, e.g. 02, from a month name
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $monthName String: month name
|
2004-09-03 16:51:45 +00:00
|
|
|
* @return string ISO month name
|
|
|
|
|
*/
|
|
|
|
|
function makeIsoMonth( $monthName ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$n = $this->xMonths[$this->lang->lc( $monthName )];
|
2004-06-08 23:56:09 +00:00
|
|
|
return sprintf( '%02d', $n );
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
2006-04-19 15:46:24 +00:00
|
|
|
* @param $year String: Year name
|
2004-09-03 16:51:45 +00:00
|
|
|
* @return string ISO year name
|
|
|
|
|
*/
|
|
|
|
|
function makeIsoYear( $year ) {
|
2003-11-20 13:12:41 +00:00
|
|
|
# Assumes the year is in a nice format, as enforced by the regex
|
|
|
|
|
if ( substr( $year, -2 ) == 'BC' ) {
|
2005-08-16 23:36:16 +00:00
|
|
|
$num = intval(substr( $year, 0, -3 )) - 1;
|
2003-11-20 13:12:41 +00:00
|
|
|
# PHP bug note: sprintf( "%04d", -1 ) fails poorly
|
2004-06-08 23:56:09 +00:00
|
|
|
$text = sprintf( '-%04d', $num );
|
2003-11-20 13:12:41 +00:00
|
|
|
|
|
|
|
|
} else {
|
2004-06-08 23:56:09 +00:00
|
|
|
$text = sprintf( '%04d', $year );
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-03 16:51:45 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return int|string
|
2004-09-03 16:51:45 +00:00
|
|
|
*/
|
|
|
|
|
function makeNormalYear( $iso ) {
|
2011-04-17 07:59:58 +00:00
|
|
|
if ( $iso[0] == '-' ) {
|
2005-08-16 23:36:16 +00:00
|
|
|
$text = (intval( substr( $iso, 1 ) ) + 1) . ' BC';
|
2003-11-20 13:12:41 +00:00
|
|
|
} else {
|
2005-08-16 23:36:16 +00:00
|
|
|
$text = intval( $iso );
|
2003-11-20 13:12:41 +00:00
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
}
|