date-format.asciidoc 7.8 KB

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