Add internal timestamp wrapper wfTimestamp($outputtype,$timestamp);
authorDomas Mituzas <midom@users.mediawiki.org>
Tue, 10 Aug 2004 08:28:43 +0000 (08:28 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Tue, 10 Aug 2004 08:28:43 +0000 (08:28 +0000)
Obsoletes: wfTimestamp2Unix, wfUnix2Timestamp, wfTimestampNow;
Autodetects database, mediawiki and unix timestamps

to be done: inverted timestamp support

includes/GlobalFunctions.php

index 7df6877..a2789ab 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 # Global functions used everywhere
+# $Id$
 
 $wgNumberOfArticles = -1; # Unset
 $wgTotalViews = -1;
@@ -1073,4 +1074,40 @@ function wfRestoreWarnings() {
        wfSuppressWarnings( true );
 }
 
+# Autodetect, convert and provide timestamps of various types
+define("TS_UNIX",0);   # Standard unix timestamp
+define("TS_MW",1);     # Mediawiki concatenated string timestamp (yyyymmddhhmmss)
+define("TS_DB",2);     # Standard database timestamp (yyyy-mm-dd hh:mm:ss)
+
+function wfTimestamp($outputtype=TS_UNIX,$ts=0) {
+       if (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
+               # TS_DB
+               $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
+                           (int)$da[2],(int)$da[3],(int)$da[1]);
+       } elseif (preg_match("/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/",$ts,$da)) {
+               # TS_MW
+               $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
+                           (int)$da[2],(int)$da[3],(int)$da[1]);
+       } elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
+               # TS_UNIX
+               $uts=$ts;
+       }
+
+       if ($ts==0)
+               $uts=time();
+       switch($outputtype) {
+       case TS_UNIX:
+               return $uts;
+               break;
+       case TS_MW:
+               return gmdate( "YmdHis", $uts );
+               break;
+       case TS_DB:
+               return gmdate( "Y-m-d H:i:s", $uts );
+               break;
+       default:
+               return;
+       }       
+}
+
 ?>