Christopher Johnson (WMDE) has uploaded a new change for review.

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

Change subject: Add timezone aware dates
......................................................................

Add timezone aware dates

Change-Id: Ifda10f566590847948df30dfc7e1e895d0b83d5a
---
M src/storage/SprintBuildStats.php
M src/view/BurndownDataView.php
2 files changed, 16 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint 
refs/changes/81/172481/1

diff --git a/src/storage/SprintBuildStats.php b/src/storage/SprintBuildStats.php
index 5209514..d4ddb82 100644
--- a/src/storage/SprintBuildStats.php
+++ b/src/storage/SprintBuildStats.php
@@ -1,13 +1,19 @@
 <?php
 
 final class SprintBuildStats {
+  private $timezone;
 
-    public function buildDateArray($start, $end, $timezone) {
+  public function setTimezone ($viewer) {
+    $this->timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
+    return $this->timezone;
+  }
+
+  public function buildDateArray($start, $end, $timezone) {
 
     $period = new DatePeriod(
-        id(new DateTime("@" . $start, $timezone))->setTime(8, 0),
+        id(new DateTime("@" . $start))->setTime(2, 0)->setTimezone($timezone),
         new DateInterval('P1D'), // 1 day interval
-        id(new DateTime("@" . $end, $timezone))->modify('+1 day')->setTime(17, 
0));
+        id(new DateTime("@" . $end))->modify('+1 day')->setTime(17, 
0)->setTimezone($timezone));
 
 
     $dates = array('before' =>$this->getBurndownDate('Before Sprint'));
@@ -20,8 +26,8 @@
     return $dates;
   }
 
-  public function buildTimeSeries($start, $end, $timezone) {
-    $timeseries = array_keys($this->buildDateArray ($start, $end, $timezone));
+  public function buildTimeSeries($start, $end) {
+    $timeseries = array_keys($this->buildDateArray ($start, $end, 
$this->timezone));
     return $timeseries;
   }
 
@@ -93,7 +99,8 @@
     $future = false;
     foreach ($dates as $key => $date) {
       if ($key != 'before' AND $key != 'after') {
-        $future = new DateTime($date->getDate()) > id(new 
DateTime())->setTime(0, 0);
+        $now = id(new DateTime('now', $this->timezone));
+        $future = new DateTime($date->getDate(), $this->timezone) > $now;
       }
       $data[] = array(
           $future ? null : $date->getPointsTotal(),
diff --git a/src/view/BurndownDataView.php b/src/view/BurndownDataView.php
index 8a2888d..452339c 100644
--- a/src/view/BurndownDataView.php
+++ b/src/view/BurndownDataView.php
@@ -31,11 +31,6 @@
     return $this;
   }
 
-  public function setTimeZone ($viewer) {
-    $timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
-    return $timezone;
-  }
-
   public function render() {
     $chart = $this->buildC3Chart();
     $tasks_table = $this->buildTasksTable();
@@ -53,8 +48,9 @@
     $start = $query->getStartDate($aux_fields);
     $end = $query->getEndDate($aux_fields);
     $stats = id(new SprintBuildStats());
-    $dates = $stats->buildDateArray($start, $end, 
$this->setTimeZone($this->viewer));
-    $this->timeseries = $stats->buildTimeSeries($start, $end, 
$this->setTimeZone($this->viewer));
+    $timezone = $stats->setTimezone($this->viewer);
+    $dates = $stats->buildDateArray($start, $end, $timezone);
+    $this->timeseries = $stats->buildTimeSeries($start, $end);
 
     $tasks = $query->getTasks();
     $query->checkNull($start, $end, $tasks);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifda10f566590847948df30dfc7e1e895d0b83d5a
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to