package core_unix

  1. Overview
  2. Docs
Unix-specific portions of Core

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.1.tar.gz
md5=9370dca36f518fcea046d2752e3de22b
sha512=c4e8ce9d5885ac8fa8d554a97e1857f3a1c933e0eb5dfd4fe874412b9d09e6d0a2973b644733855553f33f5c859719228f0e6aaf3a2b7eb5befb46fc513750de

doc/src/core_unix.interval_unix/interval_unix.ml.html

Source file interval_unix.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
open! Core
module Interval = Interval_lib.Interval

module Stable = struct
  module V1 = struct
    module Time = struct
      module T = struct
        type t = Time_float_unix.Stable.V1.t Interval.Stable.V1.t
        [@@deriving sexp, bin_io, compare]
      end

      include T
      include Comparator.Stable.V1.Make (T)
    end

    module Time_ns = struct
      module T = struct
        type t = Time_ns_unix.Stable.V1.t Interval.Stable.V1.t
        [@@deriving sexp, bin_io, compare]
      end

      include T
      include Comparator.Stable.V1.Make (T)
    end
  end
end

module type S_time = Interval_unix_intf.S_time

module type Time_bound = sig
  type t [@@deriving bin_io, sexp, compare, hash]

  include Comparable.S with type t := t

  module Ofday : sig
    type t
  end

  module Zone : sig
    type t

    val local : t Lazy.t
  end

  val occurrence
    :  [ `First_after_or_at | `Last_before_or_at ]
    -> t
    -> ofday:Ofday.t
    -> zone:Zone.t
    -> t
end

module Make_time (Time : Time_bound) = struct
  include Interval.Private.Make (Time)

  let create_ending_after ?zone (open_ofday, close_ofday) ~now =
    let zone =
      match zone with
      | None -> Lazy.force Time.Zone.local
      | Some z -> z
    in
    let close_time = Time.occurrence `First_after_or_at now ~zone ~ofday:close_ofday in
    let open_time =
      Time.occurrence `Last_before_or_at close_time ~zone ~ofday:open_ofday
    in
    create open_time close_time
  ;;

  let create_ending_before ?zone (open_ofday, close_ofday) ~ubound =
    let zone =
      match zone with
      | None -> Lazy.force Time.Zone.local
      | Some z -> z
    in
    let close_time = Time.occurrence `Last_before_or_at ubound ~zone ~ofday:close_ofday in
    let open_time =
      Time.occurrence `Last_before_or_at close_time ~zone ~ofday:open_ofday
    in
    create open_time close_time
  ;;
end

module Time = Make_time (Time_float_unix)
module Time_ns = Make_time (Time_ns_unix)
OCaml

Innovation. Community. Security.