1<?php
2
3namespace Elastica\Aggregation;
4
5use Elastica\Aggregation\Traits\MissingTrait;
6
7class AutoDateHistogram extends AbstractSimpleAggregation
8{
9    use MissingTrait;
10
11    public function __construct(string $name, string $field)
12    {
13        parent::__construct($name);
14        $this->setField($field);
15    }
16
17    /**
18     * A target number of buckets.
19     * The buckets field is optional, and will default to 10 buckets if not specified.
20     *
21     * @return $this
22     */
23    public function setBuckets(int $buckets): self
24    {
25        return $this->setParam('buckets', $buckets);
26    }
27
28    /**
29     * Set the format for this aggregation.
30     * If no format is specified, then it will use the first date format specified in the field mapping.
31     *
32     * @return $this
33     */
34    public function setFormat(string $format): self
35    {
36        return $this->setParam('format', $format);
37    }
38
39    /**
40     * Set time_zone option.
41     * The time_zone parameter can be used to indicate that bucketing should use a different time zone.
42     *
43     * @return $this
44     */
45    public function setTimezone(string $timezone): self
46    {
47        return $this->setParam('time_zone', $timezone);
48    }
49
50    /**
51     * The minimum_interval allows the caller to specify the minimum rounding interval that should be used.
52     * The accepted units: year, month, day, hour, minute, second.
53     *
54     * @return $this
55     */
56    public function setMinimumInterval(string $minimumInterval): self
57    {
58        return $this->setParam('minimum_interval', $minimumInterval);
59    }
60}
61