1<?php
2
3namespace Elastica\Processor;
4
5/**
6 * Elastica DateIndexName Processor.
7 *
8 * @author Federico Panini <fpanini@gmail.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-index-name-processor.html
11 */
12class DateIndexNameProcessor extends AbstractProcessor
13{
14    use Traits\FieldTrait;
15    use Traits\IgnoreFailureTrait;
16
17    public const DEFAULT_DATE_FORMATS_VALUE = ['ISO8601'];
18    public const DEFAULT_INDEX_NAME_FORMAT_VALUE = 'yyyy-MM-dd';
19    public const DEFAULT_TIMEZONE_VALUE = 'UTC';
20    public const DEFAULT_LOCALE_VALUE = 'ENGLISH';
21
22    public function __construct(string $field, string $dateRounding)
23    {
24        $this->setField($field);
25        $this->setDateRounding($dateRounding);
26    }
27
28    /**
29     * Set date_rounding. Valid values are: y (year), M (month), w (week), d (day), h (hour), m (minute) and s (second).
30     *
31     * @return $this
32     */
33    public function setDateRounding(string $dateRounding): self
34    {
35        return $this->setParam('date_rounding', $dateRounding);
36    }
37
38    /**
39     * Set field formats. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
40     *
41     * @return $this
42     */
43    public function setDateFormats(array $formats): self
44    {
45        return $this->setParam('date_formats', $formats);
46    }
47
48    /**
49     * Set index_prefix_name.
50     *
51     * @return $this
52     */
53    public function setIndexNamePrefix(string $indexPrefixName): self
54    {
55        return $this->setParam('index_name_prefix', $indexPrefixName);
56    }
57
58    /**
59     * Set format to be used when printing parsed date. An valid Joda pattern is expected here. Default yyyy-MM-dd.
60     *
61     * @return $this
62     */
63    public function setIndexNameFormat(string $indexNameFormat): self
64    {
65        return $this->setParam('index_name_format', $indexNameFormat);
66    }
67
68    /**
69     * Set the timezone use when parsing the date. Default UTC.
70     *
71     * @return $this
72     */
73    public function setTimezone(string $timezone): self
74    {
75        return $this->setParam('timezone', $timezone);
76    }
77
78    /**
79     * Set the locale to use when parsing the date.
80     *
81     * @return $this
82     */
83    public function setLocale(string $locale): self
84    {
85        return $this->setParam('locale', $locale);
86    }
87}
88