Time.dcl 2.39 KB
Newer Older
1
definition module System.Time
2 3 4 5 6 7
/**
* This module provides an interface to the time definition of the
* C standard library.
*/

from StdString import class toString
8
import StdOverloaded
9 10 11
/**
* The resolution of the system clock ticks
*/
12
CLK_PER_SEC	:== 1000
13 14 15 16 17

/**
* The Tm record structure contains date and time information
* in a broken down format.
*/
18
:: Tm	= { sec		:: Int	// Seconds (0-61) (generally 0-59. Extra range to accommodate for leap seconds in certain systems.)
19 20 21 22 23 24 25
		  , min		:: Int	// Minutes (0-59)
		  ,	hour	:: Int	// Hour (0-23)
		  , mday	:: Int	// Day of the month (1-31)
		  , mon		:: Int	// Month (0-11)
		  , year	:: Int	// Years since 1900
		  , wday	:: Int	// Day of the week (0-6, 0 is Sunday)
		  , yday	:: Int	// Day of the year (0-365)
26
		  , isdst	:: Int  // Daylight saving time flag
27 28 29 30 31
		  }

/**
* The time data type represents a number of seconds since the epoch (1-1-1970).
*/
32
:: Timestamp	= Timestamp !Int
33 34 35
/**
* The clock data type represents a number of CPU clock ticks.
*/
36
:: Clock		= Clock !Int
37

38 39 40 41
instance toString 	Tm
instance toString 	Clock
instance toString 	Timestamp
instance == 		Timestamp
42
instance <			Timestamp
43
instance toInt		Timestamp
44 45 46 47 48 49 50 51

/**
* Get the number of clock ticks since the process start
*/
clock		:: !*World -> (!Clock, !*World)
/**
* Get the number of seconds since the epoch
*/
52
time		:: !*World -> (!Timestamp, !*World)
53 54 55 56 57 58 59 60 61
/**
* Get the current time as GMT
*/
gmTime		:: !*World -> (!Tm, !*World)
/**
* Get the current time in the local timezone
*/
localTime	:: !*World -> (!Tm, !*World)
/**
62 63
* Convert a Tm record (local time) to a Timestamp value.
* This is not a pure function as it depends on the current local time zone.
64
*/
65
mkTime		:: !Tm !*World-> (!Timestamp, !*World)
66
/**
Steffen Michels's avatar
Steffen Michels committed
67 68 69 70 71
* Convert a Tm record (UTC) to a Timestamp value.
* No time zone conversion is done.
*/
timeGm		:: !Tm -> Timestamp
/**
72 73
* Calculate the difference in seconds between two times
*/
74
diffTime	:: !Timestamp !Timestamp -> Int
75 76 77 78
/**
* Format the time structure using the format defined by C's time.h
*/
strfTime	:: !String !Tm -> String
79 80 81 82 83 84 85
/**
* Convert a timestamp to a Tm record (local time)
*/
toLocalTime	:: !Timestamp !*World -> (!Tm,!*World)
/**
* Convert a timestamp to a Tm record (GMT time)
*/
86
toGmTime :: !Timestamp -> Tm
87 88 89

derefTm :: !Int -> Tm
packTm :: !Tm -> {#Int}
90
gmTimeC :: !{#Int} -> Int
91 92 93 94 95 96

/**
 * Get subsecond precision time
 */
nsTime :: !*World -> (!Timespec, !*World)
:: Timespec = {tv_sec :: !Int, tv_nsec :: !Int}