The TIME 시그니처

The TIME 시그니처

TIME 시그니처는 특정 순간의 시각(타임스탬프)과 기간을 나타내는 타입을 정의해요.

출처: 문서

본문

시놉시스 (Synopsis)

signature TIME
structure Time :> TIME

인터페이스 (Interface)

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

설명 (Description)

eqtype time

시각과 기간을 나타내는 타입이에요.

exception Time

zeroTime은 에포크(1970-01-01 00:00:00 UTC) 시각이에요.

val zeroTime : time

now는 현재 시각을 돌려줘요.

fromReal r

toReal·fromReal, toSeconds·fromSeconds는 시각을 실수·초로 변환해요.

toReal t

toString·fromString은 시각을 문자열로 변환하거나 파싱해요.

toSeconds t

+·-·compare 연산으로 시각을 다뤄요.

toMilliseconds t

toMicroseconds t

toNanoseconds t

이 함수들은 t의 전체 초(각각 밀리초, 마이크로초, 나노초) 수를 돌려줘요. 시간 단위의 분수 부분은 버려지는데, 즉 값은 0 방향으로 반올림돼요. 따라서 t가 2.01초를 나타내면 이 함수들은 각각 2, 2010, 2010000, 2010000000을 돌려줘요. 결과를 LargeInt.int로 표현할 수 없으면 Overflow 예외가 발생해요.

fromSeconds n

fromMilliseconds n

fromMicroseconds n

fromNanoseconds n

이 함수들은 수 n을 n초(각각 밀리초, 마이크로초, 나노초)를 나타내는 시간 값으로 변환해요. 결과를 시간 타입으로 표현할 수 없으면 Time 예외가 발생해요.

t1 + t2

t1과 t2를 모두 구간으로 해석할 때, t1의 길이에 t2의 길이를 더한 시간 구간을 돌려줘요. 동등하게, t1을 절대 시간으로 t2를 구간으로 해석하면 t1보다 t2만큼 뒤인 절대 시간을 돌려줘요. (절대 시간은 zeroTime으로부터의 구간으로 표현되므로 두 관점은 동등해요.) 결과를 시간 값으로 표현할 수 없으면 Time 예외가 발생해요. 이 연산은 교환 법칙이 성립해요.

t1 - t2

t1과 t2를 모두 구간으로 해석할 때, t1의 길이에서 t2의 길이를 뺀 시간 구간을 돌려줘요. 동등하게, t1을 절대 시간으로 t2를 구간으로 해석하면 t1보다 t2만큼 앞인 절대 시간을 돌려주고, t1과 t2를 모두 절대 시간으로 해석하면 t1과 t2 사이의 구간을 돌려줘요. (절대 시간은 zeroTime으로부터의 구간으로 표현되므로 모든 관점은 동등해요.) 결과를 시간 값으로 표현할 수 없으면 Time 예외가 발생해요.

compare (t1, t2)

시간 구간 t1이 t2보다 짧으면 LESS, 같으면 EQUAL, 길면 GREATER를 돌려줘요. 또는 절대 시간 t1이 t2보다 이르면 LESS, 일치하면 EQUAL, 늦으면 GREATER를 돌려줘요.

val < : time * time -> bool
val <= : time * time -> bool
val > : time * time -> bool
val >= : time * time -> bool

두 시간 사이에 해당 관계가 성립하면 true를 돌려줘요.

val now : unit -> time

현재 시간이에요. 보통 절대 시간, 즉 함수 호출이 이루어진 시점으로 해석돼요. now는 보통 예외를 발생시키지 않지만, 표현할 수 없는 시점에 호출되면 발생할 수 있어요.

fmt n t

toString t

이 함수들은 t를 초로 나타낸 십진수를 담은 문자열을 돌려줘요. fmt를 쓰면 분수 부분이 n자리 소수로 반올림돼요. n = 0이면 분수 부분이 없어야 해요. n < 0이면 Size 예외가 발생해요. toString은 t를 소수 3자리로 반올림해요. fmt 3 t와 동등해요. 예:

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]+)와 일치하는 초 수 문자열을 인식해요. 초기 공백은 무시돼요. 두 함수 모두 값이 구문상 맞지만 표현할 수 없으면 Time을 발생시켜요. scan 함수는 문자 소스 src와 리더 getc를 받아 src에서 시간 값을 파싱하려고 해요. src의 접두부가 나타내는 시간 값 t에 대해 SOME(t,r)을 돌려주는데 r은 src의 나머지예요. src의 어떤 접두부도 시간 값 표현이 아니면 NONE을 돌려줘요. fromString 함수는 문자열 s에서 시간 값을 파싱해, s의 접두부가 나타내는 시간 값 t에 대해 SOME(t)를, s의 어떤 접두부도 시간 값 표현이 아니면 NONE을 돌려줘요. 이 함수는 StringCvt.scanString scan과 동등하다는 점에 유의하세요.## 더 알아보기 (Learn more)

  • [ Top | Parent | Contents | Index | Root ] 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).