aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/tools_test.ml6
-rwxr-xr-xtools.ml8
2 files changed, 8 insertions, 6 deletions
diff --git a/tests/tools_test.ml b/tests/tools_test.ml
index 9afc611..b64afbc 100755
--- a/tests/tools_test.ml
+++ b/tests/tools_test.ml
@@ -68,7 +68,7 @@ module TestDate = struct
let test_get_julian_day ctx = begin
let result = Tools.Date.get_julian_day 2016 01 01
- and expected = (Num.num_of_int 2457389) in
+ and expected = (Num.num_of_int 42370) in
(* Check that the num is round *)
assert_equal true (Num.is_integer_num result);
@@ -88,7 +88,7 @@ module TestDate = struct
y2 m2 d2
in
- let result = Tools.Date.date_from_julian_day @@ Num.num_of_int 2415753
+ let result = Tools.Date.date_from_julian_day @@ Num.num_of_int 734
and expected = (1902, 01, 03) in
assert_equal
@@ -100,7 +100,7 @@ module TestDate = struct
let test_parse_time ctx = begin
let result = Tools.Date.from_string "1902-01-03T12:34:56"
- and expected = (Num.num_of_string "13045069031/5400") in
+ and expected = (Num.num_of_string "3966431/5400") in
(* =2415753.52425925925925925925 *)
assert_equal
~cmp:Num.(=/)
diff --git a/tools.ml b/tools.ml
index 0cf8fe6..f4befa5 100755
--- a/tools.ml
+++ b/tools.ml
@@ -268,19 +268,21 @@ module Date = struct
+ day
+ b
+ 1720995
-(* + 2415019 (* Shift to 30/12/1899 *) *)
+ - 2415019 (* Shift to 30/12/1899 *)
|> Num.num_of_int
end
let date_from_julian_day day = begin
+ let shift_day = Num.floor_num day
+ |> Num.add_num (Num.num_of_int 2415019) in
- let z = Num.int_of_num (Num.floor_num day) in
+ let z = Num.int_of_num shift_day in
let f =
if z >= 2299161 then
(* We use the Num module here to prevent overflow *)
- let day' = Num.(((num_of_int 4) */ day +/ (num_of_int 274277)) // (num_of_int 146097))
+ let day' = Num.(((num_of_int 4) */ shift_day +/ (num_of_int 274277)) // (num_of_int 146097))
|> Num.floor_num
|> Num.int_of_num in
z + 1401 + ((day' * 3) / 4) - 38