From 842058ca77f94451d429f9339e55cef0e4129225 Mon Sep 17 00:00:00 2001 From: Michael Wizner Date: Sun, 7 Jun 2020 22:57:30 +0100 Subject: [PATCH] Add Date::atStartOfDay function. --- backend/libexecution/libdate.ml | 18 ++++++++++++++++++ backend/test/test_other_libs.ml | 7 +++++++ 2 files changed, 25 insertions(+) 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 46f1583bf5..66e1180b34 100644 --- a/backend/test/test_other_libs.ml +++ b/backend/test/test_other_libs.ml @@ -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]])) ; ()