mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-17 11:04:22 +01:00
working date parsing
This commit is contained in:
parent
50740b7b91
commit
7845ab4818
1 changed files with 38 additions and 21 deletions
|
@ -91,37 +91,54 @@ defmodule Philomena.Search.Lexer do
|
||||||
ymd_sep = ignore(string("-"))
|
ymd_sep = ignore(string("-"))
|
||||||
hms_sep = ignore(string(":"))
|
hms_sep = ignore(string(":"))
|
||||||
iso8601_sep = ignore(choice([string("T"), string("t"), space]))
|
iso8601_sep = ignore(choice([string("T"), string("t"), space]))
|
||||||
iso8601_tzsep = choice([string("+"), string("-")])
|
iso8601_tzsep =
|
||||||
|
choice([
|
||||||
|
string("+") |> replace(1),
|
||||||
|
string("-") |> replace(-1)
|
||||||
|
])
|
||||||
zulu = ignore(choice([string("Z"), string("z")]))
|
zulu = ignore(choice([string("Z"), string("z")]))
|
||||||
|
|
||||||
"""
|
date_part =
|
||||||
absolute_date =
|
|
||||||
year
|
year
|
||||||
|> optional(
|
|> optional(
|
||||||
concat(ymd_sep, month)
|
ymd_sep
|
||||||
|
|> concat(month)
|
||||||
|> optional(
|
|> optional(
|
||||||
concat(ymd_sep, day)
|
ymd_sep
|
||||||
|
|> concat(day)
|
||||||
|> optional(
|
|> optional(
|
||||||
concat(iso8601_sep, hour)
|
iso8601_sep
|
||||||
|> optional(
|
|> optional(
|
||||||
concat(hms_sep, minute)
|
hour
|
||||||
|> optional(
|
|> optional(
|
||||||
concat(hms_sep, second)
|
hms_sep
|
||||||
|
|> concat(minute)
|
||||||
|
|> optional(
|
||||||
|
concat(hms_sep, second)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|> optional(
|
|> tag(:date)
|
||||||
choice([
|
|
||||||
concat(iso8601_tzsep, tz_hour)
|
timezone_part =
|
||||||
|> optional(
|
choice([
|
||||||
concat(hms_sep, tz_minute)
|
iso8601_tzsep
|
||||||
),
|
|> concat(tz_hour)
|
||||||
zulu
|
|> optional(
|
||||||
])
|
hms_sep
|
||||||
)
|
|> concat(tz_minute)
|
||||||
"""
|
)
|
||||||
|
|> tag(:timezone),
|
||||||
|
zulu
|
||||||
|
])
|
||||||
|
|
||||||
|
absolute_date =
|
||||||
|
date_part
|
||||||
|
|> optional(timezone_part)
|
||||||
|
|> tag(:absolute_date)
|
||||||
|
|
||||||
relative_date =
|
relative_date =
|
||||||
integer(min: 1)
|
integer(min: 1)
|
||||||
|
@ -139,10 +156,10 @@ defmodule Philomena.Search.Lexer do
|
||||||
|> tag(:relative_date)
|
|> tag(:relative_date)
|
||||||
|
|
||||||
date =
|
date =
|
||||||
# choice([
|
choice([
|
||||||
# absolute_date,
|
absolute_date,
|
||||||
relative_date
|
relative_date
|
||||||
# ])
|
])
|
||||||
|
|
||||||
boost = ignore(string("^")) |> unwrap_and_tag(number, :boost)
|
boost = ignore(string("^")) |> unwrap_and_tag(number, :boost)
|
||||||
fuzz = ignore(string("~")) |> unwrap_and_tag(number, :fuzz)
|
fuzz = ignore(string("~")) |> unwrap_and_tag(number, :fuzz)
|
||||||
|
|
Loading…
Reference in a new issue