Revision: 2966
          https://sourceforge.net/p/mrbs/code/2966/
Author:   cimorrison
Date:     2015-01-20 16:50:33 +0000 (Tue, 20 Jan 2015)
Log Message:
-----------
Converted get_duration() to use the new getPeriodInterval() function.

Modified Paths:
--------------
    mrbs/trunk/web/functions.inc

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2015-01-20 16:09:46 UTC (rev 2965)
+++ mrbs/trunk/web/functions.inc        2015-01-20 16:50:33 UTC (rev 2966)
@@ -565,19 +565,31 @@
 //    $translate      boolean whether to translate into the browser language
 function get_duration($start_time, $end_time, $enable_periods, $translate=TRUE)
 {
+  global $periods;
+  
   $result = array();
-  $result['duration'] = $end_time - $start_time;
-  // Need to make DST correct in opposite direction to entry creation
-  // so that user see what he expects to see
-  $result['duration'] -= cross_dst($start_time, $end_time);
+
   if ($enable_periods)
   {
-    $time = getdate($start_time);
-    $start_period = $time['minutes'];
-    toPeriodString($start_period, $result['duration'], $result['dur_units'], 
$translate);
+    $periods_per_day = count($periods);
+    $n_periods = getPeriodInterval($start_time, $end_time);  // this handles 
DST
+    if (($n_periods % $periods_per_day) == 0)
+    {
+      $result['duration'] =  intval($n_periods/$periods_per_day);
+      $result['dur_units'] = ($translate) ? get_vocab('days') : 'days';
+    }
+    else
+    {
+      $result['duration'] = $n_periods;
+      $result['dur_units'] = ($translate) ? get_vocab('periods') : 'periods';
+    }
   }
   else
   {
+    $result['duration'] = $end_time - $start_time;
+    // Need to make DST correct in opposite direction to entry creation
+    // so that user see what he expects to see
+    $result['duration'] -= cross_dst($start_time, $end_time);
     toTimeString($result['duration'], $result['dur_units'], $translate);
   }
   return $result;
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to