Kiln » babybearparser
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

Dates!

Changeset 2d328d5a9b48

Parent 17b2b6ad680b

by Profile picture of User 138Hao Lian <hao@fogcreek.com>

Changes to one file · Browse files at 2d328d5a9b48 Showing diff from parent 17b2b6ad680b Diff from another changeset...

 
29
30
31
 
 
 
 
 
 
 
32
33
34
 
45
46
47
48
 
49
50
51
52
 
 
 
 
 
 
53
54
55
 
29
30
31
32
33
34
35
36
37
38
39
40
41
 
52
53
54
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@@ -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 = ' '