Remove direct dependency towards dates_calc from the compiler

The dependency should only go through the `Runtime` module
This commit is contained in:
Louis Gesbert 2024-05-02 15:57:19 +02:00
parent a8635f0e61
commit 4d412027d0
5 changed files with 13 additions and 19 deletions

View File

@ -375,7 +375,7 @@ let rec translate_expr
(try
Runtime.date_of_numbers date.literal_date_year
date.literal_date_month date.literal_date_day
with Dates_calc.Dates.InvalidDate ->
with Failure _ ->
Message.error ~pos
"There is an error in this date, it does not correspond to a \
correct calendar day")

View File

@ -1051,13 +1051,13 @@ module UserFacing = struct
and some others not, adding confusion. *)
let date (lang : Global.backend_lang) ppf d =
let y, m, d = Dates_calc.Dates.date_to_ymd d in
let y, m, d = Runtime.date_to_years_months_days d in
match lang with
| En | Pl -> Format.fprintf ppf "%04d-%02d-%02d" y m d
| Fr -> Format.fprintf ppf "%02d/%02d/%04d" d m y
let duration (lang : Global.backend_lang) ppf dr =
let y, m, d = Dates_calc.Dates.period_to_ymds dr in
let y, m, d = Runtime.duration_to_years_months_days dr in
let rec filter0 = function
| (0, _) :: (_ :: _ as r) -> filter0 r
| x :: r -> x :: List.filter (fun (n, _) -> n <> 0) r

View File

@ -8,7 +8,6 @@
re
zarith
zarith_stubs_js
dates_calc
shared_ast)
(preprocess
(pps sedlex.ppx visitors.ppx)))

View File

@ -206,11 +206,16 @@ let day_of_month_of_date (d : date) : integer =
(* This could fail, but is expected to only be called with known, already
validated arguments by the generated code *)
let date_of_numbers (year : int) (month : int) (day : int) : date =
Dates_calc.Dates.make_date ~year ~month ~day
try Dates_calc.Dates.make_date ~year ~month ~day
with Dates_calc.Dates.InvalidDate ->
failwith "date_of_numbers: invalid date"
let date_to_string (d : date) : string =
Format.asprintf "%a" Dates_calc.Dates.format_date d
let date_to_years_months_days (d : date) : int * int * int =
Dates_calc.Dates.date_to_ymd d
let first_day_of_month = Dates_calc.Dates.first_day_of_month
let last_day_of_month = Dates_calc.Dates.last_day_of_month
@ -219,19 +224,6 @@ let duration_of_numbers (year : int) (month : int) (day : int) : duration =
let duration_to_string (d : duration) : string =
Format.asprintf "%a" Dates_calc.Dates.format_period d
(* breaks previous format *)
(* let x, y, z = CalendarLib.Date.Period.ymd d in
* let to_print =
* List.filter (fun (a, _) -> a <> 0) [x, "years"; y, "months"; z, "days"]
* in
* match to_print with
* | [] -> "empty duration"
* | _ ->
* Format.asprintf "%a"
* (Format.pp_print_list
* ~pp_sep:(fun fmt () -> Format.fprintf fmt ",@ ")
* (fun fmt (d, l) -> Format.fprintf fmt "%d %s" d l))
* to_print *)
let duration_to_years_months_days (d : duration) : int * int * int =
Dates_calc.Dates.period_to_ymds d

View File

@ -315,10 +315,12 @@ val year_of_date : date -> integer
val date_to_string : date -> string
val date_of_numbers : int -> int -> int -> date
(** Usage: [date_of_numbers year month day] *)
(** Usage: [date_of_numbers year month day].
@raise Failure on invalid inputs *)
val first_day_of_month : date -> date
val last_day_of_month : date -> date
val date_to_years_months_days : date -> int * int * int
(**{2 Durations} *)
@ -326,6 +328,7 @@ val duration_of_numbers : int -> int -> int -> duration
(** Usage : [duration_of_numbers year mounth day]. *)
val duration_to_years_months_days : duration -> int * int * int
(**{2 Times} *)
val duration_to_string : duration -> string