Skip to content

Commit

Permalink
Change get_data_DMY() to return all requested values
Browse files Browse the repository at this point in the history
Changed the logic in PHPFina.php for get_data_DMY() to:
1. When storing the value in the array, remove the "$time<$end" as this was preventing the return of the last value and is also not required as the 'break' will prevent going past the end. This was clso ausing disparity with get_data() for the same date ranges
2. 'streamlined' the loop by making $increment a value which is defined once outside of the loop
  • Loading branch information
CDuffers committed Jan 10, 2018
1 parent 47e5fe0 commit eabd806
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Modules/feed/engine/PHPFina.php
Expand Up @@ -350,7 +350,10 @@ public function get_data($name,$start,$end,$interval,$skipmissing,$limitinterval
public function get_data_DMY($id,$start,$end,$mode,$timezone)
{
if ($mode!="daily" && $mode!="weekly" && $mode!="monthly") return false;


$increment="+1 day";
if ($mode=="weekly") $increment="+1 week";
if ($mode=="monthly") $increment="+1 month";
$start = intval($start/1000);
$end = intval($end/1000);

Expand All @@ -371,7 +374,7 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
if ($mode=="monthly") $date->modify("first day of this month");

$n = 0;
while($n<10000) // max itterations
while($n<10000) // max iterations
{
$time = $date->getTimestamp();
if ($time>$end) break;
Expand All @@ -392,13 +395,11 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
$value = null;
}
}
if ($time>=$start && $time<$end) {
if ($time>=$start) {
$data[] = array($time*1000,$value);
}

if ($mode=="daily") $date->modify("+1 day");
if ($mode=="weekly") $date->modify("+1 week");
if ($mode=="monthly") $date->modify("+1 month");

$date->modify($increment);
$n++;
}

Expand Down

0 comments on commit eabd806

Please sign in to comment.