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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="Start" href="index.html">
<link rel="previous" href="Period.html">
<link rel="next" href="Date.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Time_Zone" rel="Chapter" href="Time_Zone.html">
<link title="Period" rel="Chapter" href="Period.html">
<link title="Time" rel="Chapter" href="Time.html">
<link title="Date" rel="Chapter" href="Date.html">
<link title="Calendar" rel="Chapter" href="Calendar.html">
<link title="Printer" rel="Chapter" href="Printer.html"><link title="Datatypes" rel="Section" href="#1_Datatypes">
<link title="Constructors" rel="Section" href="#1_Constructors">
<link title="Conversions" rel="Section" href="#1_Conversions">
<link title="Getters" rel="Section" href="#1_Getters">
<link title="Boolean operations on times" rel="Section" href="#1_Booleanoperationsontimes">
<link title="Coercions" rel="Section" href="#1_Coercions">
<link title="Period" rel="Section" href="#1_Period">
<link title="Arithmetic operations on times and periods" rel="Section" href="#1_Arithmeticoperationsontimesandperiods">
<title>Time</title>
</head>
<body>
<div class="navbar"><a href="Period.html">Previous</a>
<a href="index.html">Up</a>
<a href="Date.html">Next</a>
</div>
<center><h1>Module <a href="type_Time.html">Time</a></h1></center>
<br>
<pre><span class="keyword">module</span> Time: <code class="code">sig</code> <a href="Time.html">..</a> <code class="code">end</code></pre>Time operations.<br>
<hr width="100%">
<br>
This module implements operations on times.
A time is a triple (hour, minute, second).
<p>
If minutes and seconds do not belong to <code class="code">[0; 59]</code>, they are coerced into this
interval. For example, the time "30 hours, 60 minutes, 80 seconds" is coerced
to the time "31 hours, 1 minute, 20 seconds".
<p>
Each time is interpreted in the current time zone (given by
<code class="code">Time_Zone.current ()</code>). So, if you change the time zone (by
<code class="code">Time_Zone.change</code>), each time consequently changes.
If you want to express a time in another time zone (and do not affect
others times), use the <code class="code">convert</code> function.<br>
<br>
<a name="1_Datatypes"></a>
<h1>Datatypes</h1><br>
<pre><span class="keyword">type</span> <a name="TYPEt"></a><code class="type"></code>t </pre>
<div class="info">
Type of a time.<br>
</div>
<pre><span class="keyword">type</span> <a name="TYPEfield"></a><code class="type"></code>field = <code class="type">[ `Hour | `Minute | `Second ]</code> </pre>
<div class="info">
The different fields of a time.<br>
</div>
<br>
<a name="1_Constructors"></a>
<h1>Constructors</h1><br>
<pre><span class="keyword">val</span> <a name="VALmake"></a>make : <code class="type">int -> int -> int -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">make hour minute second</code> makes the time hour-minute-second.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALlmake"></a>lmake : <code class="type">?hour:int -> ?minute:int -> ?second:int -> unit -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
Labelled version of <code class="code">make</code>. The default value is <code class="code">0</code> for each argument.<br>
<b>Since</b> 1.05<br>
</div>
<pre><span class="keyword">val</span> <a name="VALnow"></a>now : <code class="type">unit -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
The current time based on <code class="code">Time_Zone.current ()</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmidnight"></a>midnight : <code class="type">unit -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">midnight ()</code> is midnight (expressed in the current time zone).
So, it has always the same behaviour as <code class="code">make 0 0 0</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmidday"></a>midday : <code class="type">unit -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">midday ()</code> is midday (expressed in the current time zone).
So, it has always the same behaviour as <code class="code">make 12 0 0</code>.<br>
</div>
<br>
<a name="1_Conversions"></a>
<h1>Conversions</h1><br>
<pre><span class="keyword">val</span> <a name="VALconvert"></a>convert : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time_Zone.html#TYPEt">Time_Zone.t</a> -> <a href="Time_Zone.html#TYPEt">Time_Zone.t</a> -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">convert t t1 t2</code> converts the time <code class="code">t</code> expressed in the time zone <code class="code">t1</code>
to the same time expressed in the time zone <code class="code">t2</code>.\\
E.g.
<code class="code">convert (make 20 0 0) (Time_Zone.GMT_Plus 2) (Time_Zone.GMT_Plus 4)</code>
returns the time 22-0-0.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_gmt"></a>from_gmt : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">from_gmt t</code> is equivalent to
<code class="code">convert t Time_Zone.GMT (Time_Zone.current ())</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALto_gmt"></a>to_gmt : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">to_gmt t</code> is equivalent to
<code class="code">convert t (Time_Zone.current ()) Time_Zone.GMT</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALnormalize"></a>normalize : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a> * int</code></pre><div class="info">
<code class="code">normalize t</code> returns <code class="code">t</code> such that <code class="code">hour t</code> $\in <code class="code">0; 23</code>$. The second
component of the result is the number of days needed by the modification.
E.g. <code class="code">normalize (make 22 0 0)</code> returns the time 22-0-0 and 0, <code class="code">normalize
(make 73 0 0)</code> returns the time 1-0-0 and 3 and <code class="code">normalize (make (-73) 0
0)</code> returns the time 23-0-0 and (-4).<br>
</div>
<br>
<a name="1_Getters"></a>
<h1>Getters</h1><br>
<pre><span class="keyword">val</span> <a name="VALhour"></a>hour : <code class="type"><a href="Time.html#TYPEt">t</a> -> int</code></pre><div class="info">
Hour. E.g. <code class="code">hour (make 20 0 0)</code> returns 20.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALminute"></a>minute : <code class="type"><a href="Time.html#TYPEt">t</a> -> int</code></pre><div class="info">
Minute. E.g. <code class="code">minute (make 20 10 0)</code> returns 10.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALsecond"></a>second : <code class="type"><a href="Time.html#TYPEt">t</a> -> int</code></pre><div class="info">
Second. E.g. <code class="code">second (make 20 10 5)</code> returns 5.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALto_seconds"></a>to_seconds : <code class="type"><a href="Time.html#TYPEt">t</a> -> int</code></pre><div class="info">
Number of seconds of a time.
E.g. <code class="code">to_seconds (make 1 2 3)</code> returns <code class="code">3600 + 120 + 3 = 3723</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALto_minutes"></a>to_minutes : <code class="type"><a href="Time.html#TYPEt">t</a> -> float</code></pre><div class="info">
Number of minutes of a time. The resulting fractional part represents
seconds. E.g. <code class="code">to_minutes (make 1 2 3)</code> returns <code class="code">60 + 2 + 0.05 = 62.05</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALto_hours"></a>to_hours : <code class="type"><a href="Time.html#TYPEt">t</a> -> float</code></pre><div class="info">
Number of hours of a time. The resulting fractional part represents
minutes and seconds.
E.g. <code class="code">to_hours (make 1 3 0)</code> returns <code class="code">1 + 0.05 = 1.05</code>.<br>
</div>
<br>
<a name="1_Booleanoperationsontimes"></a>
<h1>Boolean operations on times</h1><br>
<pre><span class="keyword">val</span> <a name="VALcompare"></a>compare : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a> -> int</code></pre><div class="info">
Comparison function between two times.
Same behaviour as <code class="code">Pervasives.compare</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALequal"></a>equal : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a> -> bool</code></pre><div class="info">
Equality function between two times. Same behaviour as <code class="code">(=)</code>.<br>
<b>Since</b> 1.09.0<br>
</div>
<pre><span class="keyword">val</span> <a name="VALis_pm"></a>is_pm : <code class="type"><a href="Time.html#TYPEt">t</a> -> bool</code></pre><div class="info">
Return <code class="code">true</code> is the time is before midday in the current time zone;
<code class="code">false</code> otherwise.
E.g. both <code class="code">is_pm (make 10 0 0)</code> and <code class="code">is_pm (make 34 0 0)</code> return <code class="code">true</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALis_am"></a>is_am : <code class="type"><a href="Time.html#TYPEt">t</a> -> bool</code></pre><div class="info">
Return <code class="code">true</code> is the time is after midday in the current time zone;
<code class="code">false</code> otherwise.
E.g. both <code class="code">is_am (make 20 0 0)</code> and <code class="code">is_am (make 44 0 0)</code> return <code class="code">true</code>.<br>
</div>
<br>
<a name="1_Coercions"></a>
<h1>Coercions</h1><br>
<pre><span class="keyword">val</span> <a name="VALfrom_seconds"></a>from_seconds : <code class="type">int -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
Inverse of <code class="code">to_seconds</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_minutes"></a>from_minutes : <code class="type">float -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
Inverse of <code class="code">to_minutes</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfrom_hours"></a>from_hours : <code class="type">float -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
Inverse of <code class="code">to_hours</code>.<br>
</div>
<br>
<a name="1_Period"></a>
<h1>Period</h1><br>
<pre><span class="keyword">module</span> <a href="Time.Period.html">Period</a>: <code class="code">sig</code> <a href="Time.Period.html">..</a> <code class="code">end</code></pre><br>
<a name="1_Arithmeticoperationsontimesandperiods"></a>
<h1>Arithmetic operations on times and periods</h1><br>
<pre><span class="keyword">val</span> <a name="VALadd"></a>add : <code class="type"><a href="Time.html#TYPEt">t</a> -> Period.t -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">app t p</code> returns <code class="code">t + p</code>.
E.g. <code class="code">add (make 20 0 0) (Period.minute 70)</code> returns the time 21:10:0.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALsub"></a>sub : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEt">t</a> -> Period.t</code></pre><div class="info">
<code class="code">sub t1 t2</code> returns the period between <code class="code">t1</code> and <code class="code">t2</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrem"></a>rem : <code class="type"><a href="Time.html#TYPEt">t</a> -> Period.t -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">rem t p</code> is equivalent to <code class="code">add t (Period.opp p)</code>.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALnext"></a>next : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEfield">field</a> -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">next t f</code> returns the time corresponding to the next specified field.
E.g <code class="code">next (make 20 3 31) `Minute</code> returns the time 20:04:31.
(i.e. one minute later).<br>
</div>
<pre><span class="keyword">val</span> <a name="VALprev"></a>prev : <code class="type"><a href="Time.html#TYPEt">t</a> -> <a href="Time.html#TYPEfield">field</a> -> <a href="Time.html#TYPEt">t</a></code></pre><div class="info">
<code class="code">prev t f</code> returns the time corresponding to the previous specified
field.
E.g <code class="code">prev (make 20 3 31) `Second</code> returns the time 20:03:30
(i.e. one second ago).<br>
</div>
</body></html>
|