1<?php
2
3namespace Elastica\Processor;
4
5/**
6 * Elastica Date Processor.
7 *
8 * @author Federico Panini <fpanini@gmail.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-processor.html
11 */
12class Date extends AbstractProcessor
13{
14    const DEFAULT_TARGET_FIELD_VALUE = '@timestamp';
15    const DEFAULT_TIMEZONE_VALUE = 'UTC';
16    const DEFAULT_LOCALE_VALUE = 'ENGLISH';
17
18    /**
19     * Date constructor.
20     *
21     * @param string $field
22     * @param array  $formats
23     */
24    public function __construct(string $field, array $formats)
25    {
26        $this->setField($field);
27        $this->setFormats($formats);
28    }
29
30    /**
31     * Set field.
32     *
33     * @param string $field
34     *
35     * @return $this
36     */
37    public function setField(string $field): self
38    {
39        return $this->setParam('field', $field);
40    }
41
42    /**
43     * Set field format. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
44     *
45     * @param array $formats
46     *
47     * @return $this
48     */
49    public function setFormats(array $formats): self
50    {
51        return $this->setParam('formats', $formats);
52    }
53
54    /**
55     * Set target_field. Default value @timestamp.
56     *
57     * @param string $targetField
58     *
59     * @return $this
60     */
61    public function setTargetField(string $targetField): self
62    {
63        return $this->setParam('target_field', $targetField);
64    }
65
66    /**
67     * Set the timezone use when parsing the date. Default UTC.
68     *
69     * @param string $timezone
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     * @param string $locale
82     *
83     * @return $this
84     */
85    public function setLocale(string $locale): self
86    {
87        return $this->setParam('locale', $locale);
88    }
89}
90