Date.php 1.7 KB

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