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 DateProcessor extends AbstractProcessor
13{
14    use Traits\FieldTrait;
15    use Traits\IgnoreFailureTrait;
16    use Traits\TargetFieldTrait;
17
18    public const DEFAULT_TARGET_FIELD_VALUE = '@timestamp';
19    public const DEFAULT_TIMEZONE_VALUE = 'UTC';
20    public const DEFAULT_LOCALE_VALUE = 'ENGLISH';
21
22    public function __construct(string $field, array $formats)
23    {
24        $this->setField($field);
25        $this->setFormats($formats);
26    }
27
28    /**
29     * Set field format. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
30     *
31     * @return $this
32     */
33    public function setFormats(array $formats): self
34    {
35        return $this->setParam('formats', $formats);
36    }
37
38    /**
39     * Set the timezone use when parsing the date. Default UTC.
40     *
41     * @return $this
42     */
43    public function setTimezone(string $timezone): self
44    {
45        return $this->setParam('timezone', $timezone);
46    }
47
48    /**
49     * Set the locale to use when parsing the date.
50     *
51     * @return $this
52     */
53    public function setLocale(string $locale): self
54    {
55        return $this->setParam('locale', $locale);
56    }
57}
58