date-format.asciidoc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. [[mapping-date-format]]
  2. == Date Format
  3. When defining a `date` type, or when defining `date_formats` in the
  4. `object` mapping, the value of it is the actual date format that will be
  5. used to parse the string representation of the date. There are built in
  6. formats supported, as well as complete custom one.
  7. The parsing of dates uses http://joda-time.sourceforge.net/[Joda]. The
  8. default date parsing used if no format is specified is
  9. http://joda-time.sourceforge.net/api-release/org/joda/time/format/ISODateTimeFormat.html#dateOptionalTimeParser[ISODateTimeFormat.dateOptionalTimeParser]().
  10. An extension to the format allow to define several formats using `||`
  11. separator. This allows to define less strict formats that can be used,
  12. for example, the `yyyy/MM/dd HH:mm:ss||yyyy/MM/dd` format will parse
  13. both `yyyy/MM/dd HH:mm:ss` and `yyyy/MM/dd`. The first format will also
  14. act as the one that converts back from milliseconds to a string
  15. representation.
  16. [float]
  17. === Date Math
  18. The `date` type supports using date math expression when using it in a
  19. query/filter (mainly make sense in `range` query/filter).
  20. The expression starts with an "anchor" date, which can be either `now`
  21. or a date string (in the applicable format) ending with `||`. It can
  22. then follow by a math expression, supporting `+`, `-` and `/`
  23. (rounding). The units supported are `M` (month), `w` (week), `h` (hour),
  24. `m` (minute), and `s` (second).
  25. Here are some samples: `now+1h`, `now+1h+1m`, `now+1h/d`,
  26. `2012-01-01||+1M/d`.
  27. Note, when doing `range` type searches, and the upper value is
  28. inclusive, the rounding will properly be rounded to the ceiling instead
  29. of flooring it.
  30. [float]
  31. === Built In Formats
  32. The following tables lists all the defaults ISO formats supported:
  33. [cols="<,<",options="header",]
  34. |=======================================================================
  35. |Name |Description
  36. |`basic_date`|A basic formatter for a full date as four digit year, two
  37. digit month of year, and two digit day of month (yyyyMMdd).
  38. |`basic_date_time`|A basic formatter that combines a basic date and time,
  39. separated by a 'T' (yyyyMMdd'T'HHmmss.SSSZ).
  40. |`basic_date_time_no_millis`|A basic formatter that combines a basic date
  41. and time without millis, separated by a 'T' (yyyyMMdd'T'HHmmssZ).
  42. |`basic_ordinal_date`|A formatter for a full ordinal date, using a four
  43. digit year and three digit dayOfYear (yyyyDDD).
  44. |`basic_ordinal_date_time`|A formatter for a full ordinal date and time,
  45. using a four digit year and three digit dayOfYear
  46. (yyyyDDD'T'HHmmss.SSSZ).
  47. |`basic_ordinal_date_time_no_millis`|A formatter for a full ordinal date
  48. and time without millis, using a four digit year and three digit
  49. dayOfYear (yyyyDDD'T'HHmmssZ).
  50. |`basic_time`|A basic formatter for a two digit hour of day, two digit
  51. minute of hour, two digit second of minute, three digit millis, and time
  52. zone offset (HHmmss.SSSZ).
  53. |`basic_time_no_millis`|A basic formatter for a two digit hour of day,
  54. two digit minute of hour, two digit second of minute, and time zone
  55. offset (HHmmssZ).
  56. |`basic_t_time`|A basic formatter for a two digit hour of day, two digit
  57. minute of hour, two digit second of minute, three digit millis, and time
  58. zone off set prefixed by 'T' ('T'HHmmss.SSSZ).
  59. |`basic_t_time_no_millis`|A basic formatter for a two digit hour of day,
  60. two digit minute of hour, two digit second of minute, and time zone
  61. offset prefixed by 'T' ('T'HHmmssZ).
  62. |`basic_week_date`|A basic formatter for a full date as four digit
  63. weekyear, two digit week of weekyear, and one digit day of week
  64. (xxxx'W'wwe).
  65. |`basic_week_date_time`|A basic formatter that combines a basic weekyear
  66. date and time, separated by a 'T' (xxxx'W'wwe'T'HHmmss.SSSZ).
  67. |`basic_week_date_time_no_millis`|A basic formatter that combines a basic
  68. weekyear date and time without millis, separated by a 'T'
  69. (xxxx'W'wwe'T'HHmmssZ).
  70. |`date`|A formatter for a full date as four digit year, two digit month
  71. of year, and two digit day of month (yyyy-MM-dd).
  72. |`date_hour`|A formatter that combines a full date and two digit hour of
  73. day.
  74. |`date_hour_minute`|A formatter that combines a full date, two digit hour
  75. of day, and two digit minute of hour.
  76. |`date_hour_minute_second`|A formatter that combines a full date, two
  77. digit hour of day, two digit minute of hour, and two digit second of
  78. minute.
  79. |`date_hour_minute_second_fraction`|A formatter that combines a full
  80. date, two digit hour of day, two digit minute of hour, two digit second
  81. of minute, and three digit fraction of second
  82. (yyyy-MM-dd'T'HH:mm:ss.SSS).
  83. |`date_hour_minute_second_millis`|A formatter that combines a full date,
  84. two digit hour of day, two digit minute of hour, two digit second of
  85. minute, and three digit fraction of second (yyyy-MM-dd'T'HH:mm:ss.SSS).
  86. |`date_optional_time`|a generic ISO datetime parser where the date is
  87. mandatory and the time is optional.
  88. |`date_time`|A formatter that combines a full date and time, separated by
  89. a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).
  90. |`date_time_no_millis`|A formatter that combines a full date and time
  91. without millis, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ssZZ).
  92. |`hour`|A formatter for a two digit hour of day.
  93. |`hour_minute`|A formatter for a two digit hour of day and two digit
  94. minute of hour.
  95. |`hour_minute_second`|A formatter for a two digit hour of day, two digit
  96. minute of hour, and two digit second of minute.
  97. |`hour_minute_second_fraction`|A formatter for a two digit hour of day,
  98. two digit minute of hour, two digit second of minute, and three digit
  99. fraction of second (HH:mm:ss.SSS).
  100. |`hour_minute_second_millis`|A formatter for a two digit hour of day, two
  101. digit minute of hour, two digit second of minute, and three digit
  102. fraction of second (HH:mm:ss.SSS).
  103. |`ordinal_date`|A formatter for a full ordinal date, using a four digit
  104. year and three digit dayOfYear (yyyy-DDD).
  105. |`ordinal_date_time`|A formatter for a full ordinal date and time, using
  106. a four digit year and three digit dayOfYear (yyyy-DDD'T'HH:mm:ss.SSSZZ).
  107. |`ordinal_date_time_no_millis`|A formatter for a full ordinal date and
  108. time without millis, using a four digit year and three digit dayOfYear
  109. (yyyy-DDD'T'HH:mm:ssZZ).
  110. |`time`|A formatter for a two digit hour of day, two digit minute of
  111. hour, two digit second of minute, three digit fraction of second, and
  112. time zone offset (HH:mm:ss.SSSZZ).
  113. |`time_no_millis`|A formatter for a two digit hour of day, two digit
  114. minute of hour, two digit second of minute, and time zone offset
  115. (HH:mm:ssZZ).
  116. |`t_time`|A formatter for a two digit hour of day, two digit minute of
  117. hour, two digit second of minute, three digit fraction of second, and
  118. time zone offset prefixed by 'T' ('T'HH:mm:ss.SSSZZ).
  119. |`t_time_no_millis`|A formatter for a two digit hour of day, two digit
  120. minute of hour, two digit second of minute, and time zone offset
  121. prefixed by 'T' ('T'HH:mm:ssZZ).
  122. |`week_date`|A formatter for a full date as four digit weekyear, two
  123. digit week of weekyear, and one digit day of week (xxxx-'W'ww-e).
  124. |`week_date_time`|A formatter that combines a full weekyear date and
  125. time, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ).
  126. |`weekDateTimeNoMillis`|A formatter that combines a full weekyear date
  127. and time without millis, separated by a 'T' (xxxx-'W'ww-e'T'HH:mm:ssZZ).
  128. |`week_year`|A formatter for a four digit weekyear.
  129. |`weekyearWeek`|A formatter for a four digit weekyear and two digit week
  130. of weekyear.
  131. |`weekyearWeekDay`|A formatter for a four digit weekyear, two digit week
  132. of weekyear, and one digit day of week.
  133. |`year`|A formatter for a four digit year.
  134. |`year_month`|A formatter for a four digit year and two digit month of
  135. year.
  136. |`year_month_day`|A formatter for a four digit year, two digit month of
  137. year, and two digit day of month.
  138. |=======================================================================
  139. [float]
  140. === Custom Format
  141. Allows for a completely customizable date format explained
  142. http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html[here].