Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date::atStartOfDay function. #2546

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1330,6 +1330,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