12345678910111213141516171819202122232425262728293031323334353637383940openBaseincludeTimmy.TimezonemoduleJs=Js_of_ocaml.Jsletnow()=Ptime_clock.now()|>Timmy.Time.of_ptime(* JS Date's getTimezoneOffset is designed so that date + offset = GMT. Timmy
computes the offset from GMT, date - offset = GMT. *)lettimezone_local=letoffset_calendar_time_s~date:(year,month,day)~time:(hours,minutes,seconds)=let()=letis_input_ok=Result.is_ok(Timmy.Date.of_tuple(year,month,day))&&Result.is_ok(Timmy.Daytime.of_tuple(hours,minutes,seconds))inmatchis_input_okwith|true->()|false->Fmt.failwith"Given date and time %04i-%02i-%02i at %02i:%02i:%02i are not valid"yearmonthdayhoursminutessecondsinletjs_date=new%jsJs.date_secyear(month-1)dayhoursminutessecondsinjs_date##getTimezoneOffset*60*-1andoffset_timestamp_s~unix_timestamp=let()=ifInt64.compare0Lunix_timestamp>0thenFmt.failwith"Given timestamp is negative"inletjs_date=new%jsJs.date_fromTimeValue(Int64.to_floatunix_timestamp*.1000.0)injs_date##getTimezoneOffset*60*-1inof_implementation~offset_calendar_time_s~offset_timestamp_slettoday()=Timmy.Date.of_time~timezone:timezone_local@@now()