Skip to content

Commit c8ef848

Browse files
committed
Added Elastica\Aggregation\DateHistogram::setTimezone
1 parent 4a62c5c commit c8ef848

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

changes.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CHANGES
22

33
2015-04-08
4-
- Added Elastica\Aggregation\DateHistogram::setOffset
5-
- Added deprecation notice to setPreOffset, setPostOffset and setPreZoneAdjustLargeInterval methods in Elastica\Aggregation\DateHistogram
4+
- Added new methods to Elastica\Aggregation\DateHistogram: setOffset, setTimezone
5+
- Following methods in Elastica\Aggregation\DateHistogram marked as deprecated: setPreOffset, setPostOffset, setPreZone, setPostZone, setPreZoneAdjustLargeInterval
66

77
2015-04-07
88
- [BC break] Elastica\Query\QueryString::setLowercaseExpandedTerms removed

lib/Elastica/Aggregation/DateHistogram.php

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class DateHistogram extends Histogram
1111
{
1212
/**
1313
* Set pre-rounding based on interval
14+
*
15+
* @deprecated Option "pre_zone" is deprecated as of ES 1.5. Use "time_zone" instead
16+
*
1417
* @param string $preZone
1518
* @return $this
1619
*/
@@ -21,6 +24,9 @@ public function setPreZone($preZone)
2124

2225
/**
2326
* Set post-rounding based on interval
27+
*
28+
* @deprecated Option "post_zone" is deprecated as of ES 1.5. Use "time_zone" instead
29+
*
2430
* @param string $postZone
2531
* @return $this
2632
*/
@@ -29,6 +35,17 @@ public function setPostZone($postZone)
2935
return $this->setParam("post_zone", $postZone);
3036
}
3137

38+
/**
39+
* Set time_zone option
40+
*
41+
* @param string
42+
* @return $this
43+
*/
44+
public function setTimezone($timezone)
45+
{
46+
return $this->setParam('time_zone', $timezone);
47+
}
48+
3249
/**
3350
* Set pre-zone adjustment for larger time intervals (day and above)
3451
*

test/lib/Elastica/Test/Aggregation/DateHistogramTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,23 @@ public function testSetOffsetWorks()
6969

7070
$this->assertEquals('2014-01-29T00:19:40.000Z', $results['buckets'][0]['key_as_string']);
7171
}
72+
73+
public function testSetTimezone()
74+
{
75+
$agg = new DateHistogram('hist', 'created', '1h');
76+
77+
$agg->setTimezone('-02:30');
78+
79+
$expected = array(
80+
'date_histogram' => array(
81+
'field' => 'created',
82+
'interval' => '1h',
83+
'time_zone' => '-02:30',
84+
),
85+
);
86+
87+
$this->assertEquals($expected, $agg->toArray());
88+
89+
$this->assertInstanceOf('Elastica\Aggregation\DateHistogram', $agg->setTimezone('-02:30'));
90+
}
7291
}

0 commit comments

Comments
 (0)