Skip to content

Commit

Permalink
Merge pull request #2546 from mwz/add-date-at-start-of-day
Browse files Browse the repository at this point in the history
Add Date::atStartOfDay function.
  • Loading branch information
pbiggar authored Jun 8, 2020
2 parents c28de56 + 842058c commit de173e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/libexecution/libdate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,22 @@ let fns : expr fn list =
| args ->
fail args)
; preview_safety = Safe
; deprecated = false }
; { prefix_names = ["Date::atStartOfDay"]
; infix_names = []
; parameters = [par "date" TDate]
; return_type = TDate
; description = "Returns the Date with the time set to midnight"
; func =
InProcess
(function
| _, [DDate d] ->
d
|> Time.to_date ~zone:Time.Zone.utc
|> (fun x ->
Time.of_date_ofday Time.Zone.utc x Time.Ofday.start_of_day)
|> DDate
| args ->
fail args)
; preview_safety = Safe
; deprecated = false } ]
7 changes: 7 additions & 0 deletions backend/test/test_other_libs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,13 @@ let t_date_functions_work () =
"Date >= works - equality"
(DBool true)
(exec_ast' (binop "Date::>=" later_date later_date)) ;
check_dval
"Date::atStartOfDay works"
(Dval.dstr_of_string_exn "2019-07-28T00:00:00Z")
(exec_ast'
(pipe
date
[fn "Date::atStartOfDay" [pipeTarget]; fn "toString" [pipeTarget]])) ;
()


Expand Down

0 comments on commit de173e1

Please sign in to comment.