1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
current-seconds
seconds->date
date
current-milliseconds
current-inexact-milliseconds
current-process-milliseconds
current-gc-milliseconds
time-apply
time
14.5.1 Date Utilities
date->string
date-display-format
find-seconds
date->julian/ scalinger
julian/ scalinger->string
Version: 4.0.2

 

14.5 Time

(current-seconds)  exact-integer?

Returns the current time in seconds. This time is always an exact integer based on a platform-specific starting date (with a platform-specific minimum and maximum value).

The value of (current-seconds) increases as time passes (increasing by 1 for each second that passes). The current time in seconds can be compared with a time returned by file-or-directory-modify-seconds.

(seconds->date secs-n)  date?

  secs-n : exact-integer?

Takes secs-n, a platform-specific time in seconds returned by current-seconds or file-or-directory-modify-seconds, and returns an instance of the date structure type. If secs-n is too small or large, the exn:fail exception is raised.

The value returned by current-seconds or file-or-directory-modify-seconds is not portable among platforms. Convert a time in seconds using seconds->date when portability is needed.

(struct

 

date

 (

second

 

 

 

 

minute

 

 

 

 

hour

 

 

 

 

day

 

 

 

 

month

 

 

 

 

year

 

 

 

 

week-day

 

 

 

 

year-day

 

 

 

 

dst?

 

 

 

 

time-zone-offset)

 

 

#:transparent)

  second : (integer-in 0 61)

  minute : (integer-in 0 59)

  hour : (integer-in 0 23)

  day : (integer-in 1 31)

  month : (integer-in 1 12)

  year : exact-nonnegative-integer?

  week-day : (integer-in 0 6)

  year-day : (integer-in 0 365)

  dst? : boolean?

  time-zone-offset : exact-integer?

Represents a date. For the second field, values of 60 and 61 are for unusual, but possible for leap-seconds. The year-day field reaches 365 only in leap years.

The time-zone-offset field reports the number of seconds east of GMT for the current time zone (e.g., Pacific Standard Time is -28800), an exact integer.

The value produced for the time-zone-offset field tends to be sensitive to the value of the TZ environment variable, especially on Unix platforms; consult the system documentation (usually under tzset) for details.

See also the scheme/date library.

(current-milliseconds)  exact-integer?

Returns the current “time” in fixnum milliseconds (possibly negative). This time is based on a platform-specific starting date or on the machine’s startup time. Since the result is a fixnum, the value increases only over a limited (though reasonably long) time.

(current-inexact-milliseconds)  real?

Like current-milliseconds, but the result never decreases (until the machine is turned off).

(current-process-milliseconds)  exact-integer?

Returns the amount of processor time in fixnum milliseconds that has been consumed by the Scheme process on the underlying operating system. (Under Unix and Mac OS X, this includes both user and system time.) The precision of the result is platform-specific, and since the result is a fixnum, the value increases only over a limited (though reasonably long) time.

(current-gc-milliseconds)  exact-integer?

Returns the amount of processor time in fixnum milliseconds that has been consumed by Scheme’s garbage collection so far. This time is a portion of the time reported by (current-process-milliseconds), and is similarly limited.

(time-apply proc arg ...)

 

 

list?

exact-integer?

exact-integer?

exact-integer?

  proc : procedure?

  arg : any/c

Collects timing information for a procedure application.

Four values are returned: a list containing the result(s) of applying proc, the number of milliseconds of CPU time required to obtain this result, the number of “real” milliseconds required for the result, and the number of milliseconds of CPU time (included in the first result) spent on garbage collection.

The reliability of the timing numbers depends on the platform. If multiple MzScheme threads are running, then the reported time may include work performed by other threads.

(time expr)

Reports time-apply-style timing information for the evaluation of expr directly to the current output port. The result is the result of expr.

14.5.1 Date Utilities

 (require scheme/date)

(date->string date [time?])  string?

  date : date?

  time? : any/c = #f

Converts a date to a string. The returned string contains the time of day only if time?. See also date-display-format.

(date-display-format)

 

 

(one-of/c 'american

          'chinese

          'german

          'indian

          'irish

          'iso-8601

          'rfc2822

          'julian)

(date-display-format format)  void?

  

format

 

:

 

(one-of/c 'american

          'chinese

          'german

          'indian

          'irish

          'iso-8601

          'rfc2822

          'julian)

Parameter that determines the date string format. The initial format is 'american.

(find-seconds

 

second

 

 

 

 

 

 

minute

 

 

 

 

 

 

hour

 

 

 

 

 

 

day

 

 

 

 

 

 

month

 

 

 

 

 

 

year)

 

 

exact-integer?

  second : (integer-in 0 61)

  minute : (integer-in 0 59)

  hour : (integer-in 0 23)

  day : (integer-in 1 31)

  month : (integer-in 1 12)

  year : exact-nonnegative-integer?

Finds the representation of a date in platform-specific seconds. The arguments correspond to the fields of the date structure. If the platform cannot represent the specified date, an error is signaled, otherwise an integer is returned.

(date->julian/scalinger date)  exact-integer?

  date : date?

Converts a date structure (up to 2099 BCE Gregorian) into a Julian date number. The returned value is not a strict Julian number, but rather Scalinger’s version, which is off by one for easier calculations.

(julian/scalinger->string date-number)  string?

  date-number : exact-integer?

Converts a Julian number (Scalinger’s off-by-one version) into a string.