X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMWTimestamp.php;h=6f3be73f4d33e69a8ff5c4d51e6091e26fd436ed;hb=90e1b22166b00e096930d90029bd9826843298b2;hp=f2bd6ba56919463e03918b3d8e6e847c0146fed0;hpb=246bebe8216228a2482927680e330c3b15a7334c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index f2bd6ba569..6f3be73f4d 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -56,7 +56,7 @@ class MWTimestamp { * * @since 1.20 * - * @param bool|string $timestamp Timestamp to set, or false for current time + * @param bool|string|int|float $timestamp Timestamp to set, or false for current time */ public function __construct( $timestamp = false ) { $this->setTimestamp( $timestamp ); @@ -74,6 +74,7 @@ class MWTimestamp { * @throws TimestampException */ public function setTimestamp( $ts = false ) { + $m = array(); $da = array(); $strtime = ''; @@ -87,9 +88,9 @@ class MWTimestamp { # TS_EXIF } elseif ( preg_match( '/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) { # TS_MW - } elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) { + } elseif ( preg_match( '/^(-?\d{1,13})(\.\d+)?$/D', $ts, $m ) ) { # TS_UNIX - $strtime = "@$ts"; // http://php.net/manual/en/datetime.formats.compound.php + $strtime = "@{$m[1]}"; // http://php.net/manual/en/datetime.formats.compound.php } elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) { # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6 $strtime = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3", @@ -366,6 +367,26 @@ class MWTimestamp { return $this->timestamp->getTimezone(); } + /** + * Get the localized timezone message, if available. + * + * Premade translations are not shipped as format() may return whatever the + * system uses, localized or not, so translation must be done through wiki. + * + * @since 1.25 + * @return Message The localized timezone message + */ + public function getTimezoneMessage() { + $tzMsg = $this->format( 'T' ); // might vary on DST changeover! + $key = 'timezone-' . strtolower( trim( $tzMsg ) ); + $msg = wfMessage( $key ); + if ( $msg->exists() ) { + return $msg; + } else { + return new RawMessage( $tzMsg ); + } + } + /** * Format the timestamp in a given format. *