Skip to content
Snippets Groups Projects
Unverified Commit b640d763 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Merge pull request #7390 from paychex/include-today-sql-queries

Fix include today not working for past/next date filters on SQL queries
parents e08b3a5f 4e908be3
No related branches found
No related tags found
No related merge requests found
......@@ -113,15 +113,15 @@
;; e.g. past30days = past 30 days, not including partial data for today ({:include-current false})
;; past30days~ = past 30 days, *including* partial data for today ({:include-current true})
{:parser (regex->parser #"past([0-9]+)(day|week|month|year)s(~?)", [:int-value :unit :include-current?])
:range (fn [{:keys [unit int-value unit-range to-period]} dt]
:range (fn [{:keys [unit int-value unit-range to-period include-current?]} dt]
(unit-range (t/minus dt (to-period int-value))
(t/minus dt (to-period 1))))
(t/minus dt (to-period (if (seq include-current?) 0 1)))))
:filter (fn [{:keys [unit int-value include-current?]} field]
["TIME_INTERVAL" field (- int-value) unit {:include-current (boolean (seq include-current?))}])}
{:parser (regex->parser #"next([0-9]+)(day|week|month|year)s" [:int-value :unit])
:range (fn [{:keys [unit int-value unit-range to-period]} dt]
(unit-range (t/plus dt (to-period 1))
{:parser (regex->parser #"next([0-9]+)(day|week|month|year)s(~?)" [:int-value :unit :include-current?])
:range (fn [{:keys [unit int-value unit-range to-period include-current?]} dt]
(unit-range (t/plus dt (to-period (if (seq include-current?) 0 1)))
(t/plus dt (to-period int-value))))
:filter (fn [{:keys [unit int-value]} field]
["TIME_INTERVAL" field int-value unit])}
......
......@@ -18,19 +18,25 @@
(expect {:end "2016-04-18"} (test-date->range "~2016-04-18"))
(expect {:end "2016-06-06", :start "2016-06-04"} (test-date->range "past3days"))
(expect {:end "2016-06-07", :start "2016-06-04"} (test-date->range "past3days~"))
(expect {:end "2016-06-06", :start "2016-05-31"} (test-date->range "past7days"))
(expect {:end "2016-06-06", :start "2016-05-08"} (test-date->range "past30days"))
(expect {:end "2016-05-31", :start "2016-04-01"} (test-date->range "past2months"))
(expect {:end "2016-06-30", :start "2016-04-01"} (test-date->range "past2months~"))
(expect {:end "2016-05-31", :start "2015-05-01"} (test-date->range "past13months"))
(expect {:end "2015-12-31", :start "2015-01-01"} (test-date->range "past1years"))
(expect {:end "2016-12-31", :start "2015-01-01"} (test-date->range "past1years~"))
(expect {:end "2015-12-31", :start "2000-01-01"} (test-date->range "past16years"))
(expect {:end "2016-06-10", :start "2016-06-08"} (test-date->range "next3days"))
(expect {:end "2016-06-10", :start "2016-06-07"} (test-date->range "next3days~"))
(expect {:end "2016-06-14", :start "2016-06-08"} (test-date->range "next7days"))
(expect {:end "2016-07-07", :start "2016-06-08"} (test-date->range "next30days"))
(expect {:end "2016-08-31", :start "2016-07-01"} (test-date->range "next2months"))
(expect {:end "2016-08-31", :start "2016-06-01"} (test-date->range "next2months~"))
(expect {:end "2017-07-31", :start "2016-07-01"} (test-date->range "next13months"))
(expect {:end "2017-12-31", :start "2017-01-01"} (test-date->range "next1years"))
(expect {:end "2017-12-31", :start "2016-01-01"} (test-date->range "next1years~"))
(expect {:end "2032-12-31", :start "2017-01-01"} (test-date->range "next16years"))
(expect {:end "2016-06-07", :start "2016-06-07"} (test-date->range "thisday"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment