PLT Scheme provides basic, but important ways of manipulating time and
dates.
(current-seconds) returns the current time in seconds, and
it is always an exact integer based on a platform-specific starting
date, or
epoch.
The value of
(current-seconds) increases as time passes (increasing
by 1 for each second that passes), and since people are not used to
working with seconds, PLT provides
(seconds->date n) which takes
n, a platform-specific time in seconds (as returned by
current-seconds), and returns an instance of the date structure type, which has the following fields:
-
second : 0 to 61 (60 and 61 are for unusual leap-seconds)
-
minute : 0 to 59
-
hour : 0 to 23
-
day : 1 to 31
-
month : 1 to 12
-
year : e.g., 1996
-
week-day : 0 (Sunday) to 6 (Saturday)
-
year-day : 0 to 365 (364 in non-leap years)
-
dst? : #t (daylight savings time) or #f
-
time-zone-offset : the number of seconds east of GMT for this
time zone (e.g., Pacific Standard Time is -28800), an exact integer 39
So, for instance printing the current year is as simple as:
(let* ((seconds (current-seconds))
(today (seconds->date seconds)))
(display (date-year today))
(newline))
PLT Scheme also includes a Dates library,
date.ss, which is part of
Mzlib collection, and as part of the
SRFI collection, PLT supports
SRFI 19,
Time Data Types and Procedures, which is a very complete library of date, and time
related procedures.
We will discuss these libraries in the following recipes.
--
FranciscoSolsona - 28 Apr 2004