1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)letps_count_in_s=1_000_000_000_000Lexternalposix_clock_gettime_s_ns:unit->int64*int64="ocaml_posix_clock_gettime_s_ns"letnow_d_ps()=letsecs,ns=posix_clock_gettime_s_ns()inletdays=Int64.divsecs86_400Linletrem_s=Int64.remsecs86_400Linletfrac_ps=Int64.mulns1000Linletrem_ps=Int64.mulrem_sps_count_in_sin(Int64.to_intdays,Int64.addrem_psfrac_ps)letcurrent_tz_offset_s()=letnow=Unix.gettimeofday()inletutc=Unix.gmtimenowinletlocal=Unix.localtimenowinletd_day=local.Unix.tm_yday-utc.Unix.tm_ydayinletd_hour=local.Unix.tm_hour-utc.Unix.tm_hourinletd_min=(d_hour*60)+(local.Unix.tm_min-utc.Unix.tm_min)inletmin_per_day=24*60inletd_min=matchd_daywith|0->d_min(* same day *)(* day wrapped *)|1->d_min+min_per_day|-1->d_min-min_per_day(* year wrapped *)|_->ifd_min<-1thend_min+min_per_dayelsed_min-min_per_dayinSome(d_min*60)externalposix_clock_period_ns:unit->int64="ocaml_posix_clock_period_ns"letperiod_d_ps()=letperiod_ns=posix_clock_period_ns()inmatchperiod_nswith0L->None|ns->Some(0,Int64.mulns1000L)