Skip to content
This repository
Browse code

[enhance] 32 bits port: Time now compliant, so are cookies

So basically, Opa works on 32 bits architectures!
There may remain specific issues, though. (hlnet?)
  • Loading branch information...
commit 865ee952d5ac911fb02ed8ae674e28c299f0620e 1 parent d7a3b3f
François-Régis Sinot authored

Showing 2 changed files with 52 additions and 22 deletions. Show diff stats Hide diff stats

  1. +1 0  libbase/_tags
  2. +51 22 libbase/time.ml
1  libbase/_tags
@@ -8,6 +8,7 @@
8 8 <cactutf.ml>: use_ulex
9 9 <sgzip.ml> : use_zip
10 10 <xml.ml>: with_mlstate_debug
  11 +<time.ml>: with_mlstate_debug
11 12
12 13 # This warnings are generated by the preprocessor : what a shame !
13 14 <indexer.ml>: warn_z
73 libbase/time.ml
@@ -15,18 +15,65 @@
15 15 You should have received a copy of the GNU Affero General Public License
16 16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 17 *)
18   -type t = int
19 18
20   -(* FIXME, proper type for Time.tm *)
  19 +#<Ifstatic:OCAML_WORD_SIZE 64>
  20 +
  21 +type t = int
21 22 type tm = Unix.tm
22 23
  24 +let infinity = max_int
  25 +
23 26 let of_unix_time t = int_of_float (t *. 1000.)
24 27 let to_unix_time t = float_of_int t /. 1000.
25 28 let fmi = float_of_int max_int
26 29 let of_unix_time_inf t = let t1000 = t *. 1000.0 in if t1000 >= fmi then max_int else int_of_float t1000
27 30
  31 +let adjust_mktime res ms =
  32 + if res < 0 then res - ms else res + ms
  33 +
  34 +let zero = 0
  35 +let is_positive t = t > 0
  36 +let add t1 t2 = if t1 = infinity || t2 = infinity then infinity else t1 + t2
  37 +let difference t1 t2 = if t1 = infinity then zero else if t2 = infinity then infinity else t2 - t1
  38 +
  39 +let milliseconds v = v
  40 +let in_milliseconds t = t
  41 +let in_seconds t = float_of_int t /. 1000.
  42 +let round_to_sec t = t - (t mod 1000)
  43 +
  44 +let gmt_msec time = (abs time) mod 1000
  45 +let local_msec time = (abs time) mod 1000
  46 +
  47 +#<Else>
  48 +
  49 +type t = float
  50 +type tm = Unix.tm
  51 +
  52 +let infinity = infinity
  53 +
  54 +let of_unix_time t = t
  55 +let to_unix_time t = t
  56 +let of_unix_time_inf t = t
  57 +
  58 +let adjust_mktime res ms =
  59 + (if res < 0. then (-.) else (+.)) res (float_of_int ms /. 1000.)
  60 +
  61 +let zero = 0.
  62 +let is_positive t = t > 0.
  63 +let add t1 t2 = t1 +. t2
  64 +let difference t1 t2 = t2 -. t1
  65 +
  66 +let milliseconds v = float_of_int v /. 1000.
  67 +let in_milliseconds t = int_of_float (t *. 1000.)
  68 +let in_seconds t = t
  69 +let round_to_sec t = floor t
  70 +
  71 +let gmt_msec time = int_of_float (snd (modf (abs_float time)) *. 1000.)
  72 +let local_msec time = gmt_msec time
  73 +
  74 +#<End>
  75 +
28 76 let now () = of_unix_time (Unix.gettimeofday ())
29   -let infinity = max_int
30 77
31 78 let process_utime () = of_unix_time (Unix.times ()).Unix.tms_utime
32 79 let process_stime () = of_unix_time (Unix.times ()).Unix.tms_stime
@@ -38,8 +85,6 @@ let sleep = Unix.sleep
38 85 let gmtime t = Unix.gmtime (to_unix_time t)
39 86 let localtime t = Unix.localtime (to_unix_time t)
40 87
41   -(*let gmt_usec time = time mod 1000000 *)
42   -let gmt_msec time = (abs time) mod 1000
43 88 let gmt_sec time = (gmtime time).Unix.tm_sec
44 89 let gmt_min time = (gmtime time).Unix.tm_min
45 90 let gmt_hour time = (gmtime time).Unix.tm_hour
@@ -50,8 +95,6 @@ let gmt_wday time = (gmtime time).Unix.tm_wday
50 95 let gmt_yday time = (gmtime time).Unix.tm_yday
51 96 let gmt_isdst time = (gmtime time).Unix.tm_isdst
52 97
53   -(*let local_usec time = (time * 1000000) mod 1000000*)
54   -let local_msec time = (abs time) mod 1000
55 98 let local_sec time = (localtime time).Unix.tm_sec
56 99 let local_min time = (localtime time).Unix.tm_min
57 100 let local_hour time = (localtime time).Unix.tm_hour
@@ -80,36 +123,22 @@ let mktime ~year ~month ~day ~h ~min ~sec ~ms =
80 123 )
81 124 )
82 125 in
83   - if res < 0 then res - ms else res + ms
  126 + adjust_mktime res ms
84 127
85 128 let bound = Chrono.bound
86 129
87   -let zero = 0
88 130
89   -let is_positive t = t > 0
90 131 let is_infinite t = t = infinity
91 132
92 133 let is_after t1 t2 = t1 > t2
93 134 let is_before t1 t2 = t1 < t2
94 135
95   -let add t1 t2 = if t1 = infinity || t2 = infinity then infinity else t1 + t2
96   -
97   -let milliseconds v = v
98 136 let seconds v = milliseconds (v * 1000)
99 137 let seconds_float = of_unix_time
100 138 let minutes v = seconds (v * 60)
101 139 let hours v = minutes (v * 60)
102 140 let days v = hours (v * 24)
103 141
104   -let in_seconds t =
105   - float_of_int t /. 1000.
106   -
107   -let in_milliseconds t = t
108   -
109   -let round_to_sec t = t - (t mod 1000)
110   -
111   -let difference t1 t2 = if t1 = infinity then zero else if t2 = infinity then infinity else t2 - t1
112   -
113 142 let max = Pervasives.max
114 143 let min = Pervasives.min
115 144

0 comments on commit 865ee95

Please sign in to comment.
Something went wrong with that request. Please try again.