Skip to content

Commit

Permalink
fix issue influxdata#121 & add support for tz clause in QueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
daiyc committed Feb 19, 2019
1 parent 4a1efb4 commit b79e1c3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/InfluxDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class Builder
*/
protected $orderBy;

/**
* @var string
*/
protected $tz;

/**
* @param Database $db
*/
Expand Down Expand Up @@ -267,6 +272,20 @@ public function offset($count)
return $this;
}

/**
* Set the timezone
*
* @param string $timezone
*
* @return $this
*/
public function tz($timezone)
{
$this->tz = $timezone;

return $this;
}

/**
* Add retention policy to query
*
Expand Down Expand Up @@ -295,9 +314,9 @@ public function getQuery()
* @return ResultSet
* @throws \Exception
*/
public function getResultSet()
public function getResultSet($params=[])
{
return $this->db->query($this->parseQuery());
return $this->db->query($this->parseQuery(), $params);
}

/**
Expand Down Expand Up @@ -345,6 +364,14 @@ protected function parseQuery()
$query .= $this->offsetClause;
}

if (isset($this->tz)) {
//also add support for timezone offset
$tz = is_numeric(trim($this->tz,0))?
timezone_name_from_abbr('',$this->tz*3600,0):
$this->tz;
$query .= " tz('".$tz."')";
}

return $query;
}
}

0 comments on commit b79e1c3

Please sign in to comment.