add amount compare
This commit is contained in:
parent
0ab6bc7b3e
commit
21e6a47007
3 changed files with 11 additions and 10 deletions
|
|
@ -47,6 +47,14 @@ let make ~sign ~currency ~value ~fraction =
|
||||||
let currency = String.uppercase_ascii currency in
|
let currency = String.uppercase_ascii currency in
|
||||||
Ok { sign; currency; value; fraction }
|
Ok { sign; currency; value; fraction }
|
||||||
|
|
||||||
|
let compare a b =
|
||||||
|
match String.equal a.currency b.currency with
|
||||||
|
| false -> Fmt.failwith "amount compare on different currencies"
|
||||||
|
| true -> (
|
||||||
|
match Int64.unsigned_compare a.value b.value with
|
||||||
|
| 0 -> Int32.unsigned_compare a.fraction b.fraction
|
||||||
|
| n -> n)
|
||||||
|
|
||||||
module Parser = struct
|
module Parser = struct
|
||||||
open Angstrom
|
open Angstrom
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ val make :
|
||||||
fraction:Int32.t ->
|
fraction:Int32.t ->
|
||||||
(t, string) result
|
(t, string) result
|
||||||
|
|
||||||
|
(* fail on differents currencies *)
|
||||||
|
val compare : t -> t -> int
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
val of_string : string -> (t, string) result
|
val of_string : string -> (t, string) result
|
||||||
|
|
|
||||||
|
|
@ -99,16 +99,7 @@ let make_denom_group_sorted denominations =
|
||||||
let open RsaDenomGroup in
|
let open RsaDenomGroup in
|
||||||
let open RsaDenom in
|
let open RsaDenom in
|
||||||
let cmp_denom b a = Timestamp.compare a.stamp_start b.stamp_start in
|
let cmp_denom b a = Timestamp.compare a.stamp_start b.stamp_start in
|
||||||
let cmp_group =
|
let cmp_group = fun (Rsa a) (Rsa b) -> Amount.compare a.value b.value in
|
||||||
let cmp_amount a b =
|
|
||||||
(* TODO amount *)
|
|
||||||
let open Amount in
|
|
||||||
match Int64.unsigned_compare a.value b.value with
|
|
||||||
| 0 -> Int32.unsigned_compare a.fraction b.fraction
|
|
||||||
| n -> n
|
|
||||||
in
|
|
||||||
fun (Rsa a) (Rsa b) -> cmp_amount a.value b.value
|
|
||||||
in
|
|
||||||
let l =
|
let l =
|
||||||
l
|
l
|
||||||
|> List.map
|
|> List.map
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue