Changeset 2d328d5a9b48…
Parent 17b2b6ad680b…
by Hao Lian <hao@fogcreek.com>
Changes to one file · Browse files at 2d328d5a9b48 Showing diff from parent 17b2b6ad680b Diff from another changeset...
@@ -29,6 +29,13 @@
(* Utilities *)
let pipeline (f, a) = f a
+let failIfNone msg = function
+ | Some x -> preturn x
+ | None -> fail msg
+let stringToDate = function
+ | "today" -> Some DateTime.UtcNow.Date
+ | "yesterday" -> Some <| DateTime.UtcNow.Date.AddDays(-1.)
+ | s -> try DateTime.Parse s |> Some with :? FormatException -> None
let findFilter = function
| "author" -> Author
| "file" -> File
@@ -45,11 +52,17 @@let keyword = (phrase |>> Phrase) <|> (word |>> Word)
let filterName = ["author"; "file"; "project"; "repo"] |> Seq.map pstring |> choice
-let filter =
+let regularFilter =
(filterName |>> findFilter)
.>> (pchar ':')
.>>. (phrase <|> word <?> "filter argument")
|>> pipeline
+let dateWord = many1Chars <| noneOf ". "
+let fullDate = (phrase <|> dateWord) |>> stringToDate >>= failIfNone "Unrecognized date"
+let dateStart = fullDate <|>% DateTime.MinValue
+let dateEnd = fullDate <|>% DateTime.UtcNow.Date
+let dateFilter = pstring "date:" >>. dateStart .>> pstring ".." .>>. dateEnd |>> Date
+let filter = regularFilter <|> dateFilter
let atom = (filter |>> FilterAtom) <|> (keyword |>> KeywordAtom)
let spaces = many1Satisfy <| fun c -> c = ' '
|
Loading...