diff --git a/backend/libexecution/libdate.ml b/backend/libexecution/libdate.ml index f8c39b1ee0..35a4b42df1 100644 --- a/backend/libexecution/libdate.ml +++ b/backend/libexecution/libdate.ml @@ -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 } ] diff --git a/backend/test/test_other_libs.ml b/backend/test/test_other_libs.ml index 485afb3e9a..44e57b79ef 100644 --- a/backend/test/test_other_libs.ml +++ b/backend/test/test_other_libs.ml @@ -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]])) ; ()