Browse Source

#21 - documentation updated, force format option was added

Alex Trofimov 13 years ago
parent
commit
813de0c680
2 changed files with 20 additions and 6 deletions
  1. 10 3
      inc/design.inc.php
  2. 10 3
      template/scripts/BxBaseFunctions.php

+ 10 - 3
inc/design.inc.php

@@ -314,16 +314,23 @@ function getMemberLoginFormCode($sID = 'member_login_form', $sParams = '')
 }
 }
 
 
 /**
 /**
- * Output time wrapped in <time> tag
+ * Output time wrapped in <time> tag in HTML.
+ * Then time is autoformatted using JS upon page load, this is aumatically converted to user's timezone and
+ * updated in realtime in case of short periods of 'from now' time format.
+ *
+ * This is just short version for:
+ * @see BxTemplFunctions::timeForJs
+ * 
  * @param $iUnixTimestamp time as unixtimestamp
  * @param $iUnixTimestamp time as unixtimestamp
  * @param $sFormatIdentifier output format identifier
  * @param $sFormatIdentifier output format identifier
  *     @see BX_FORMAT_DATE
  *     @see BX_FORMAT_DATE
  *     @see BX_FORMAT_TIME
  *     @see BX_FORMAT_TIME
  *     @see BX_FORMAT_DATE_TIME
  *     @see BX_FORMAT_DATE_TIME
+ * @param $bForceFormat force provided format and don't use "from now" time autoformat.
  */
  */
-function bx_time_js ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE) {
+function bx_time_js ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false) {
     bx_import('BxTemplFunctions');
     bx_import('BxTemplFunctions');
-    return BxTemplFunctions::getInstance()->timeForJs ($iUnixTimestamp, $sFormatIdentifier);
+    return BxTemplFunctions::getInstance()->timeForJs ($iUnixTimestamp, $sFormatIdentifier, $bForceFormat);
 }
 }
 
 
 /**
 /**

+ 10 - 3
template/scripts/BxBaseFunctions.php

@@ -655,16 +655,23 @@ EOF;
     }
     }
 
 
     /**
     /**
-     * Output time wrapped in <time> tag
+     * Output time wrapped in <time> tag in HTML.
+     * Then time is autoformatted using JS upon page load, this is aumatically converted to user's timezone and
+     * updated in realtime in case of short periods of 'from now' time format.
+     *
+     * Short version of this function:
+     * @see bx_time_js
+     *
      * @param $iUnixTimestamp time as unixtimestamp
      * @param $iUnixTimestamp time as unixtimestamp
      * @param $sFormatIdentifier output format identifier
      * @param $sFormatIdentifier output format identifier
      *     @see BX_FORMAT_DATE
      *     @see BX_FORMAT_DATE
      *     @see BX_FORMAT_TIME
      *     @see BX_FORMAT_TIME
      *     @see BX_FORMAT_DATE_TIME
      *     @see BX_FORMAT_DATE_TIME
+     * @param $bForceFormat force provided format and don't use "from now" time autoformat.
      */
      */
-    function timeForJs ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE) {
+    function timeForJs ($iUnixTimestamp, $sFormatIdentifier = BX_FORMAT_DATE, $bForceFormat = false) {
         $sDateUTC = bx_time_utc ($iUnixTimestamp);
         $sDateUTC = bx_time_utc ($iUnixTimestamp);
-        return '<time datetime="' . $sDateUTC . '" data-bx-format="' . getParam($sFormatIdentifier) . '" data-bx-autoformat="' . getParam('sys_format_timeago') . '">' . $sDateUTC . '</time>';
+        return '<time datetime="' . $sDateUTC . '" data-bx-format="' . getParam($sFormatIdentifier) . '" data-bx-autoformat="' . ($bForceFormat ? 0 : getParam('sys_format_timeago')) . '">' . $sDateUTC . '</time>';
     }
     }
 
 
 }
 }