Toniher has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/55854


Change subject: allowing negative timestamps, BC
......................................................................

allowing negative timestamps, BC

Change-Id: I6859f1a903792b83cba80e065e4a0bdcb5d1cd32
---
M includes/Timestamp.php
1 file changed, 12 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/54/55854/1

diff --git a/includes/Timestamp.php b/includes/Timestamp.php
index 7dbfabf..a884c74 100644
--- a/includes/Timestamp.php
+++ b/includes/Timestamp.php
@@ -100,7 +100,7 @@
                        # TS_DB
                } elseif ( preg_match( '/^(\d{4}):(\d\d):(\d\d) 
(\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
                        # TS_EXIF
-               } elseif ( preg_match( 
'/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) {
+               } 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 ) ) {
                        # TS_UNIX
@@ -135,8 +135,19 @@
 
                if( !$strtime ) {
                        $da = array_map( 'intval', $da );
+       
+                       $sign = false; //we assume no sign (positive)
+                       if ( $da[1] < 0 ) { // If negative
+                               $sign = true;
+                               $da[1] = $da[1]*-1; //Turn year into positive
+                       }
+
                        $da[0] = "%04d-%02d-%02dT%02d:%02d:%02d.00+00:00";
                        $strtime = call_user_func_array( "sprintf", $da );
+                       if ( $sign ) {
+                               // We add negative sign back if necessary
+                               $strtime = "-".$strtime;
+                       }
                }
 
                try {

-- 
To view, visit https://gerrit.wikimedia.org/r/55854
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6859f1a903792b83cba80e065e4a0bdcb5d1cd32
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Toniher <toni...@cau.cat>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to