Skip to content

Commit

Permalink
js: Adapt the glue code for the JavaScript library
Browse files Browse the repository at this point in the history
  • Loading branch information
ilankri committed Jan 3, 2025
1 parent 0d7f65c commit 71c1d73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
29 changes: 18 additions & 11 deletions js/calendars_js.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
let () =
let make ~day ~month ~year kind =
Result.fold ~ok:Fun.id
~error:(fun erroneous_date -> erroneous_date.Calendars.value)
(Calendars.make ~day ~month ~year ~delta:0 kind)
in
Js_of_ocaml.Js.export "Calendars"
begin
object%js
method make day month year = { Calendars.day; month; year; delta = 0 }
method makeGregorian day month year =
make ~day ~month ~year Calendars.Gregorian

method makeJulian day month year =
make ~day ~month ~year Calendars.Julian

method makeFrench day month year =
make ~day ~month ~year Calendars.French

method makeHebrew day month year =
make ~day ~month ~year Calendars.Hebrew

method day { Calendars.day; _ } = day
method month { Calendars.month; _ } = month
method year { Calendars.year; _ } = year
Expand All @@ -11,16 +27,7 @@ let () =
method julianOfSdn = Calendars.julian_of_sdn
method frenchOfSdn = Calendars.french_of_sdn
method hebrewOfSdn = Calendars.hebrew_of_sdn
method sdnOfGregorian = Calendars.sdn_of_gregorian
method sdnOfJulian = Calendars.sdn_of_julian
method sdnOfFrench = Calendars.sdn_of_french
method sdnOfHebrew = Calendars.sdn_of_hebrew
method gregorianOfJulian = Calendars.gregorian_of_julian
method julianOfGregorian = Calendars.julian_of_gregorian
method gregorianOfFrench = Calendars.gregorian_of_french
method frenchOfGregorian = Calendars.french_of_gregorian
method gregorianOfHebrew = Calendars.gregorian_of_hebrew
method hebrewOfGregorian = Calendars.hebrew_of_gregorian
method toSdn = Calendars.to_sdn

method moonPhaseOfSdn s =
match Calendars.moon_phase_of_sdn s with
Expand Down
10 changes: 8 additions & 2 deletions lib/calendars.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ type _ kind =
| Hebrew : hebrew kind

module Unsafe : sig
type 'a date
type 'a date = private {
day : int;
month : int;
year : int;
delta : int;
kind : 'a kind;
}

val to_string : 'a date -> string
end

type 'a date = private {
type 'a date = 'a Unsafe.date = private {
day : int;
month : int;
year : int;
Expand Down

0 comments on commit 71c1d73

Please sign in to comment.