Time
structureThe structure Time provides an abstract type for representing times and time intervals, and functions for manipulating, converting, writing and reading them.
signature TIME
structure Time
: TIME
eqtype time
exception Time
val zeroTime : time
val fromReal : real -> time
val toReal : time -> real
val toSeconds : time -> int
val toMilliseconds : time -> int
val toMicroseconds : time -> int
val fromSeconds : int -> time
val fromMilliseconds : int -> time
val fromMicroseconds : int -> time
val + : (time * time) -> time
val - : (time * time) -> time
val compare : (time * time) -> order
val < : (time * time) -> bool
val <= : (time * time) -> bool
val > : (time * time) -> bool
val >= : (time * time) -> bool
val now : unit -> time
val fmt : int -> time -> string
val toString : time -> string
val fromString : string -> time option
val scan : (char, 'a) StringCvt.reader -> 'a -> (time, 'a) option
eqtype time
Implementation note:
Time values are required to have fixed-point semantics.
exception Time
zeroTime
fromReal 0.0
.
Absolute points on the time scale can be thought of as being represented as intervals starting at zeroTime. All time values are greater than or equal to zeroTime. The function Date.fromTime can be used to see which time zeroTime actually represents.
fromReal r
toReal t
toSeconds t
toMilliseconds t
toMicroseconds t
2
, 2010
and 2010000
, respectively.
fromSeconds n
fromMilliseconds n
fromMicroseconds n
t1 + t2
- (t1, t2)
compare (t1, t2)
t1 < t2
t1 <= t2
t1 > t2
t1 >= t2
true
if the corresponding relation holds between the two times.
now ()
fmt n t
Example:
fmt 3 (fromReal 1.8) = "1.800" fmt 0 (fromReal 1.8) = "2" fmt 0 zeroTime = "0"
toString t
fmt 3 t
.
fromString s
scan getc src
([0-9]+(\.[0-9]+)?)|(\.[0-9]+)
, denoting a number of (possibly fractional) seconds. Initial whitespace is ignored. Both raise Overflow when the value is syntactically correct but not representable.
scan takes a character source src and an reader getc and tries to parse a time value from src. It returns SOME (t,r)
where t
is the time value denoted by a prefix of src and r
is `the rest of' src; or it returns NONE when no prefix of src is a representation of a time value. The type of scan can also be written as
(char, 'a) StringCvt.reader -> (time, 'a) StringCvt.reader
fromString parses a time value from s, returning SOME t
where t
is the time value denoted by a prefix of s or NONE when no prefix of s is a representation of a time value. Note that the function is equivalent to StringCvt.scanString scan
.
Date, Timer, StringCvt
Last Modified January 21, 1997
Copyright © 1996 AT&T