Time
structure
signature TIME
structure Time
:> TIME
The structure Time
provides an abstract type for representing times and time intervals, and functions for manipulating, converting, writing, and reading them.
eqtype time
exception Time
val zeroTime : time
val fromReal : LargeReal.real -> time
val toReal : time -> LargeReal.real
val toSeconds : time -> LargeInt.int
val toMilliseconds : time -> LargeInt.int
val toMicroseconds : time -> LargeInt.int
val toNanoseconds : time -> LargeInt.int
val fromSeconds : LargeInt.int -> time
val fromMilliseconds : LargeInt.int -> time
val fromMicroseconds : LargeInt.int -> time
val fromNanoseconds : LargeInt.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 scan : (char, 'a) StringCvt.reader
-> (time, 'a) StringCvt.reader
val fromString : string -> time option
eqtype time
Implementation note:
Time values are required to have fixed-point semantics.
exception Time
time
or of operations over time
is not representable, or when an illegal operation has been attempted.
val zeroTime : time
fromReal
(0.0)
.
Absolute points on the time scale can be thought of as being represented as intervals starting at zeroTime
. The function Date.fromTimeLocal
can be used to see what time zeroTime
actually represents in the local timezone.
fromReal r
time
, fractions of a microsecond may be lost. It raises Time
when the result is not representable.
toReal t
real
has less precision than Time.time
(for example, when it is implemented as a single-precision float), information about microseconds or, for very large values, even seconds, may be lost.
toSeconds t
toMilliseconds t
toMicroseconds t
toNanoseconds t
2
, 2010
, 2010000
, and 2010000000
respectively. When the result is not representable by LargeInt.int
, the exception Overflow
is raised.
fromSeconds n
fromMilliseconds n
fromMicroseconds n
fromNanoseconds n
time
type, then the exception Time
is raised.
t1 + t2
zeroTime
). When the result is not representable as a time value, the exception Time
is raised. This operation is commutative.
t1 - t2
zeroTime
). When the result is not representable as a time value, the exception Time
is raised.
compare (t1, t2)
LESS
, EQUAL
, or GREATER
when the time interval t1 is shorter than, of same length as, or longer than t2, respectively, or the absolute time t1 is earlier than, coincides with, or is later than the absolute time t2.
val < : time * time -> bool
val <= : time * time -> bool
val > : time * time -> bool
val >= : time * time -> bool
true
if the corresponding relation holds between the two times.
val now : unit -> time
now
does not normally raise an exception, this may happen when it is called at a time that is not representable.
fmt n t
toString t
fmt
, the fractional part is rounded to n decimal digits. If n = 0, there should be no fractional part. Having n < 0 causes the Size
exception to be raised. toString
rounds t to 3 decimal digits. It is equivalent to fmt 3 t
.
Example:
fmt 3 (fromReal 1.8) = "1.800" fmt 0 (fromReal 1.8) = "2" fmt 0 zeroTime = "0"
scan getc src
fromString s
[+~-]?([0-9]+.[0-9]+? | .[0-9]+)Initial whitespace is ignored. Both functions raise
Time
when the value is syntactically correct but not representable.
The function scan
takes a character source src and an reader getc and tries to parse a time value from src. It returns
where t is the time value denoted by a prefix of src and r is the rest of src; or it returns SOME
(t,r)NONE
when no prefix of src is a representation of a time value.
The function fromString
parses a time value from the string s, returning
where t is the time value denoted by a prefix of s or SOME
(t)NONE
when no prefix of s is a representation of a time value. Note that this function is equivalent to
.
StringCvt.scanString
scan
Date
,StringCvt
,Timer
Generated April 12, 2004
Last Modified October 4, 1997
Comments to John Reppy.
This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.
Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.
Permission is granted for internet users to make one paper copy for their
own personal use. Further hardcopy reproduction is strictly prohibited.
Permission to distribute the HTML document electronically on any medium
other than the internet must be requested from the copyright holders by
contacting the editors.
Printed versions of the SML Basis Manual are available from Cambridge
University Press.
To order, please visit
www.cup.org (North America) or
www.cup.cam.ac.uk (outside North America). |