pax_global_header00006660000000000000000000000064144217506710014521gustar00rootroot0000000000000052 comment=af80adac6aaabca1098e502dcc9fabd8fdb4a759 time_now-0.16.0/000077500000000000000000000000001442175067100134265ustar00rootroot00000000000000time_now-0.16.0/.gitignore000066400000000000000000000000411442175067100154110ustar00rootroot00000000000000_build *.install *.merlin _opam time_now-0.16.0/CONTRIBUTING.md000066400000000000000000000044101442175067100156560ustar00rootroot00000000000000This repository contains open source software that is developed and maintained by [Jane Street][js]. Contributions to this project are welcome and should be submitted via GitHub pull requests. Signing contributions --------------------- We require that you sign your contributions. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org][dco]): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: ``` Signed-off-by: Joe Smith ``` Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with git commit -s. [dco]: http://developercertificate.org/ [js]: https://opensource.janestreet.com/ time_now-0.16.0/LICENSE.md000066400000000000000000000021461442175067100150350ustar00rootroot00000000000000The MIT License Copyright (c) 2019--2023 Jane Street Group, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. time_now-0.16.0/Makefile000066400000000000000000000004031442175067100150630ustar00rootroot00000000000000INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),) default: dune build install: dune install $(INSTALL_ARGS) uninstall: dune uninstall $(INSTALL_ARGS) reinstall: uninstall install clean: dune clean .PHONY: default install uninstall reinstall clean time_now-0.16.0/dune-project000066400000000000000000000000201442175067100157400ustar00rootroot00000000000000(lang dune 1.10)time_now-0.16.0/src/000077500000000000000000000000001442175067100142155ustar00rootroot00000000000000time_now-0.16.0/src/dune000066400000000000000000000005221442175067100150720ustar00rootroot00000000000000(library (name time_now) (public_name time_now) (libraries base jane-street-headers) (preprocess (pps ppx_base ppx_optcomp)) (preprocessor_deps config.h) (c_names time_now_stubs) (c_flags -std=c11 -fPIC) (js_of_ocaml (javascript_files runtime.js))) (rule (targets config.h) (deps) (action (copy %{lib:jst-config:config.h} config.h)))time_now-0.16.0/src/runtime.js000066400000000000000000000006631442175067100162430ustar00rootroot00000000000000///////// TIME_NOW //Provides: time_now_nanoseconds_since_unix_epoch_or_zero //Requires: caml_int64_mul, caml_int64_of_float, caml_int64_of_int32 var ms_to_nano = caml_int64_of_int32(1000*1000); function time_now_nanoseconds_since_unix_epoch_or_zero(){ var ms = Date.now(); // multiple by two - int63 integers are shifted to the left var ms_i63 = caml_int64_of_float(ms*2); return caml_int64_mul(ms_i63,ms_to_nano); } time_now-0.16.0/src/time_now.ml000066400000000000000000000012601442175067100163670ustar00rootroot00000000000000[%%import "config.h"] open! Base [%%ifdef JSC_ARCH_SIXTYFOUR] external nanoseconds_since_unix_epoch_or_zero : unit -> Int63.t = "time_now_nanoseconds_since_unix_epoch_or_zero" [@@noalloc] [%%else] external nanoseconds_since_unix_epoch_or_zero : unit -> Int63.t = "time_now_nanoseconds_since_unix_epoch_or_zero" [%%endif] [%%ifdef JSC_POSIX_TIMERS] let[@cold] gettime_failed () = failwith "clock_gettime(CLOCK_REALTIME) failed" [%%else] let[@cold] gettime_failed () = failwith "gettimeofday failed" [%%endif] let nanoseconds_since_unix_epoch () = let t = nanoseconds_since_unix_epoch_or_zero () in if Int63.( <> ) t Int63.zero then t else gettime_failed () ;; time_now-0.16.0/src/time_now.mli000066400000000000000000000000771442175067100165450ustar00rootroot00000000000000open! Base val nanoseconds_since_unix_epoch : unit -> Int63.t time_now-0.16.0/src/time_now_stubs.c000066400000000000000000000017031442175067100174230ustar00rootroot00000000000000#include "config.h" #include "ocaml_utils.h" #include #include #define NANOS_PER_SECOND 1000000000 #if defined(JSC_TIMESPEC) /* Note: this is imported noalloc if (and only if) ARCH_SIXTYFOUR is defined. * This is OK because caml_alloc_int63 doesn't actually allocate in that case. */ CAMLprim value time_now_nanoseconds_since_unix_epoch_or_zero() { struct timespec ts; if (timespec_get(&ts, TIME_UTC) != TIME_UTC) return caml_alloc_int63(0); else return caml_alloc_int63(NANOS_PER_SECOND * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec); } #else #include #include CAMLprim value time_now_nanoseconds_since_unix_epoch_or_zero() { struct timeval tp; if (gettimeofday(&tp, NULL) == -1) return caml_alloc_int63(0); else return caml_alloc_int63(NANOS_PER_SECOND * (uint64_t)tp.tv_sec + (uint64_t)tp.tv_usec * 1000); } #endif time_now-0.16.0/time_now.opam000066400000000000000000000017031442175067100161260ustar00rootroot00000000000000opam-version: "2.0" version: "v0.16.0" maintainer: "Jane Street developers" authors: ["Jane Street Group, LLC"] homepage: "https://github.com/janestreet/time_now" bug-reports: "https://github.com/janestreet/time_now/issues" dev-repo: "git+https://github.com/janestreet/time_now.git" doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/time_now/index.html" license: "MIT" build: [ ["dune" "build" "-p" name "-j" jobs] ] depends: [ "ocaml" {>= "4.14.0"} "base" {>= "v0.16" & < "v0.17"} "jane-street-headers" {>= "v0.16" & < "v0.17"} "jst-config" {>= "v0.16" & < "v0.17"} "ppx_base" {>= "v0.16" & < "v0.17"} "ppx_optcomp" {>= "v0.16" & < "v0.17"} "dune" {>= "2.0.0"} ] available: arch != "arm32" & arch != "x86_32" synopsis: "Reports the current time" description: " Provides a single function to report the current time in nanoseconds since the start of the Unix epoch. "