| 1 |
#!r6rs |
| 2 |
;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named |
| 3 |
;; LICENSE from the original collection this file is distributed with. |
| 4 |
|
| 5 |
(library (srfi :19 time) |
| 6 |
(export |
| 7 |
time-duration |
| 8 |
time-monotonic |
| 9 |
time-process |
| 10 |
time-tai |
| 11 |
time-thread |
| 12 |
time-utc |
| 13 |
current-date |
| 14 |
current-julian-day |
| 15 |
current-modified-julian-day |
| 16 |
current-time |
| 17 |
time-resolution |
| 18 |
make-time |
| 19 |
time? |
| 20 |
time-type |
| 21 |
time-nanosecond |
| 22 |
time-second |
| 23 |
set-time-type! |
| 24 |
set-time-nanosecond! |
| 25 |
set-time-second! |
| 26 |
copy-time |
| 27 |
time<=? |
| 28 |
time<? |
| 29 |
time=? |
| 30 |
time>=? |
| 31 |
time>? |
| 32 |
time-difference |
| 33 |
time-difference! |
| 34 |
add-duration |
| 35 |
add-duration! |
| 36 |
subtract-duration |
| 37 |
subtract-duration! |
| 38 |
make-date |
| 39 |
date? |
| 40 |
date-nanosecond |
| 41 |
date-second |
| 42 |
date-minute |
| 43 |
date-hour |
| 44 |
date-day |
| 45 |
date-month |
| 46 |
date-year |
| 47 |
date-zone-offset |
| 48 |
date-year-day |
| 49 |
date-week-day |
| 50 |
date-week-number |
| 51 |
date->julian-day |
| 52 |
date->modified-julian-day |
| 53 |
date->time-monotonic |
| 54 |
date->time-tai |
| 55 |
date->time-utc |
| 56 |
julian-day->date |
| 57 |
julian-day->time-monotonic |
| 58 |
julian-day->time-tai |
| 59 |
julian-day->time-utc |
| 60 |
modified-julian-day->date |
| 61 |
modified-julian-day->time-monotonic |
| 62 |
modified-julian-day->time-tai |
| 63 |
modified-julian-day->time-utc |
| 64 |
time-monotonic->date |
| 65 |
time-monotonic->julian-day |
| 66 |
time-monotonic->modified-julian-day |
| 67 |
time-monotonic->time-tai |
| 68 |
time-monotonic->time-tai! |
| 69 |
time-monotonic->time-utc |
| 70 |
time-monotonic->time-utc! |
| 71 |
time-tai->date |
| 72 |
time-tai->julian-day |
| 73 |
time-tai->modified-julian-day |
| 74 |
time-tai->time-monotonic |
| 75 |
time-tai->time-monotonic! |
| 76 |
time-tai->time-utc |
| 77 |
time-tai->time-utc! |
| 78 |
time-utc->date |
| 79 |
time-utc->julian-day |
| 80 |
time-utc->modified-julian-day |
| 81 |
time-utc->time-monotonic |
| 82 |
time-utc->time-monotonic! |
| 83 |
time-utc->time-tai |
| 84 |
time-utc->time-tai! |
| 85 |
date->string |
| 86 |
string->date) |
| 87 |
(import |
| 88 |
(rnrs) |
| 89 |
(rnrs r5rs) |
| 90 |
(rnrs mutable-strings) |
| 91 |
(prefix (srfi :19 time compat) host:) |
| 92 |
(srfi :6 basic-string-ports) |
| 93 |
(for (srfi private vanish) expand) |
| 94 |
(srfi private include)) |
| 95 |
|
| 96 |
(define-syntax define-struct |
| 97 |
(lambda (stx) |
| 98 |
(define (id-append x . r) |
| 99 |
(datum->syntax x (string->symbol |
| 100 |
(apply string-append |
| 101 |
(map (lambda (y) |
| 102 |
(if (identifier? y) |
| 103 |
(symbol->string (syntax->datum y)) |
| 104 |
y)) |
| 105 |
r))))) |
| 106 |
(syntax-case stx () |
| 107 |
((_ name (field ...) _) |
| 108 |
(with-syntax (((accessor ...) |
| 109 |
(map (lambda (x) (id-append x #'name "-" x)) |
| 110 |
#'(field ...))) |
| 111 |
((mutator ...) |
| 112 |
(map (lambda (x) (id-append x "set-" #'name "-" x "!")) |
| 113 |
#'(field ...)))) |
| 114 |
#'(define-record-type name |
| 115 |
(fields (mutable field accessor mutator) ...))))))) |
| 116 |
|
| 117 |
(define read-line get-line) |
| 118 |
|
| 119 |
(define (tm:time-error caller type value) |
| 120 |
(define (message x) |
| 121 |
(if (symbol? x) |
| 122 |
(list->string (map (lambda (c) (if (char=? #\- c) #\space c)) |
| 123 |
(string->list (symbol->string x)))) |
| 124 |
(call-with-string-output-port (lambda (sop) (write x sop))))) |
| 125 |
(apply assertion-violation |
| 126 |
caller (message type) (if value (list value) '()))) |
| 127 |
|
| 128 |
(define (my:time-helper current-time type proc) |
| 129 |
(let ((x (current-time))) |
| 130 |
(make-time type |
| 131 |
(host:time-nanosecond x) |
| 132 |
(proc (host:time-second x))))) |
| 133 |
|
| 134 |
(define (my:leap-second-helper s) (+ s (tm:leap-second-delta s))) |
| 135 |
|
| 136 |
(define (tm:current-time-utc) |
| 137 |
(my:time-helper host:current-time time-utc values)) |
| 138 |
|
| 139 |
(define (tm:current-time-tai) |
| 140 |
(my:time-helper host:current-time time-tai my:leap-second-helper)) |
| 141 |
|
| 142 |
(define (tm:current-time-monotonic) |
| 143 |
(my:time-helper host:current-time time-monotonic my:leap-second-helper)) |
| 144 |
|
| 145 |
(define (tm:current-time-thread) |
| 146 |
(my:time-helper host:cumulative-thread-time time-thread values)) |
| 147 |
|
| 148 |
(define (tm:current-time-process) |
| 149 |
(my:time-helper host:cumulative-process-time time-process values)) |
| 150 |
|
| 151 |
(define (tm:current-time-gc) |
| 152 |
(my:time-helper host:cumulative-gc-time time-gc values)) |
| 153 |
|
| 154 |
(define (time-resolution . clock-type) host:time-resolution) |
| 155 |
|
| 156 |
(define (tm:local-tz-offset) host:timezone-offset) |
| 157 |
|
| 158 |
(define eof (eof-object)) |
| 159 |
|
| 160 |
(let-syntax ((define (vanish-define define (tm:time-error-types |
| 161 |
tm:time-error |
| 162 |
tm:get-time-of-day |
| 163 |
tm:current-time-utc |
| 164 |
tm:current-time-tai |
| 165 |
tm:current-time-ms-time |
| 166 |
tm:current-time-monotonic |
| 167 |
tm:current-time-thread |
| 168 |
tm:current-time-process |
| 169 |
tm:current-time-gc |
| 170 |
time-resolution |
| 171 |
set-date-nanosecond! |
| 172 |
set-date-second! |
| 173 |
set-date-minute! |
| 174 |
set-date-hour! |
| 175 |
set-date-day! |
| 176 |
set-date-month! |
| 177 |
set-date-year! |
| 178 |
set-date-zone-offset! |
| 179 |
tm:local-tz-offset)))) |
| 180 |
(include/resolve ("srfi" "%3a19") "srfi-19.scm")) |
| 181 |
) |