jenkins-bot has submitted this change and it was merged.
Change subject: Made MWTimestamp handle UNIX floats
......................................................................
Made MWTimestamp handle UNIX floats
* This avoids "wfTimestamp() fed bogus time value" errors
that show up in the debug log on page views, do to
User::getTouched() usage.
Change-Id: I899d6edd2b59c02e618ed14f8d29dea53d866f05
---
M includes/MWTimestamp.php
M tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
2 files changed, 5 insertions(+), 3 deletions(-)
Approvals:
Parent5446: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php
index f2bd6ba..d28f88e 100644
--- a/includes/MWTimestamp.php
+++ b/includes/MWTimestamp.php
@@ -56,7 +56,7 @@
*
* @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 @@
* @throws TimestampException
*/
public function setTimestamp( $ts = false ) {
+ $m = array();
$da = array();
$strtime = '';
@@ -87,9 +88,9 @@
# 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",
diff --git a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
index bea496c..4ce51c6 100644
--- a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php
@@ -21,6 +21,7 @@
array( -30281104, TS_MW, '19690115123456', 'Negative
TS_UNIX to TS_MW' ),
array( $t, TS_UNIX, 979562096, 'TS_UNIX to TS_UNIX' ),
array( $t, TS_DB, '2001-01-15 12:34:56', 'TS_UNIX to
TS_DB' ),
+ array( $t + .01, TS_MW, '20010115123456', 'TS_UNIX
float to TS_MW' ),
array( $t, TS_ISO_8601_BASIC, '20010115T123456Z',
'TS_ISO_8601_BASIC to TS_DB' ),
--
To view, visit https://gerrit.wikimedia.org/r/232643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I899d6edd2b59c02e618ed14f8d29dea53d866f05
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits