| 1 |
;;; Ikarus Scheme -- A compiler for R6RS Scheme. |
| 2 |
;;; Copyright (C) 2006,2007,2008 Abdulaziz Ghuloum |
| 3 |
;;; |
| 4 |
;;; This program is free software: you can redistribute it and/or modify |
| 5 |
;;; it under the terms of the GNU General Public License version 3 as |
| 6 |
;;; published by the Free Software Foundation. |
| 7 |
;;; |
| 8 |
;;; This program is distributed in the hope that it will be useful, but |
| 9 |
;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
;;; General Public License for more details. |
| 12 |
;;; |
| 13 |
;;; You should have received a copy of the GNU General Public License |
| 14 |
;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
|
| 16 |
|
| 17 |
(library (ikarus system time-and-date) |
| 18 |
(export current-time time? time-second time-nanosecond |
| 19 |
time-gmt-offset) |
| 20 |
(import |
| 21 |
(except (ikarus) time current-time time? time-second |
| 22 |
time-nanosecond time-gmt-offset)) |
| 23 |
|
| 24 |
(define-struct time (msecs secs usecs)) |
| 25 |
;;; mega/seconds/micros |
| 26 |
|
| 27 |
(define (current-time) |
| 28 |
(foreign-call "ikrt_current_time" (make-time 0 0 0))) |
| 29 |
|
| 30 |
(define (time-second x) |
| 31 |
(if (time? x) |
| 32 |
(+ (* (time-msecs x) #e10e5) |
| 33 |
(time-secs x)) |
| 34 |
(die 'time-second "not a time" x))) |
| 35 |
|
| 36 |
(define (time-nanosecond x) |
| 37 |
(if (time? x) |
| 38 |
(* (time-usecs x) 1000) |
| 39 |
(die 'time-nanosecond "not a time" x))) |
| 40 |
|
| 41 |
(define (time-gmt-offset x) |
| 42 |
(if (time? x) |
| 43 |
(foreign-call "ikrt_gmt_offset" x) |
| 44 |
(die 'time-gmt-offset "not a time" x))) |
| 45 |
) |
| 46 |
|