123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152open!ImportmoduleStable=structmoduleV1=structtypet=|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec[@@derivingsexp,compare,hash,variants,equal]letfailwithf=Printf.failwithfletof_int_exni:t=matchiwith|1->Jan|2->Feb|3->Mar|4->Apr|5->May|6->Jun|7->Jul|8->Aug|9->Sep|10->Oct|11->Nov|12->Dec|_->failwithf"Month.of_int_exn %d"i();;letof_inti=trySome(of_int_exni)with|_->None;;letto_int(t:t)=matchtwith|Jan->1|Feb->2|Mar->3|Apr->4|May->5|Jun->6|Jul->7|Aug->8|Sep->9|Oct->10|Nov->11|Dec->12;;includeBinable.Stable.Of_binable.V1[@alert"-legacy"](Int)(structtypenonrect=tletto_binablet=to_intt-1letof_binablei=of_int_exn(i+1)end)endendletnum_months=12moduleT=structincludeStable.V1letall=[Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec]lethash=to_intendincludeTinclude(Hashable.Make_binable(structincludeTend):Hashable.S_binablewithtypet:=t)includeComparable.Make_binable(structincludeT(* In 108.06a and earlier, months in sexps of Maps and Sets were raw ints. From 108.07
through 109.13, the output format remained raw as before, but both the raw and
pretty format were accepted as input. From 109.14 on, the output format was
changed from raw to pretty, while continuing to accept both formats. Once we believe
most programs are beyond 109.14, we will switch the input format to no longer accept
raw. *)lett_of_sexpsexp=matchOption.try_with(fun()->Int.t_of_sexpsexp)with|Somei->of_int_exn(i+1)|None->T.t_of_sexpsexp;;end)(* Replace the overriden sexp converters from [Comparable.Make_binable] with the ordinary
symbolic converters. *)letsexp_of_t=T.sexp_of_tlett_of_sexp=T.t_of_sexpletshiftti=of_int_exn(1+Int.(%)(to_intt-1+i)num_months)letall_strings=lazy(Array.of_list(List.mapall~f:(funvariant->Sexp.to_string(sexp_of_tvariant))));;letto_string(t:t)=letall_strings=Lazy.forceall_stringsinall_strings.(to_intt-1);;letof_string=lettable=lazy(letmoduleT=String.Tableinlettable=T.create~size:num_months()inArray.iteri(Lazy.forceall_strings)~f:(funis->lett=of_int_exn(i+1)inHashtbl.settable~key:s~data:t;Hashtbl.settable~key:(String.lowercases)~data:t;Hashtbl.settable~key:(String.uppercases)~data:t);table)infunstr->matchHashtbl.find(Lazy.forcetable)strwith|Somex->x|None->failwithf"Invalid month: %s"str();;moduleExport=structtypemonth=t=|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Decend