Adding date->seconds
This commit is contained in:
parent
009ae0588e
commit
1b6b721aee
|
@ -7,6 +7,7 @@
|
|||
|
||||
(provide/contract
|
||||
[current-date (-> date?)]
|
||||
[date->seconds (date? . -> . exact-integer?)]
|
||||
[date->string ((date?) (boolean?) . ->* . string?)]
|
||||
[date-display-format (parameter/c (symbols 'american 'chinese 'german 'indian 'irish 'julian 'iso-8601 'rfc2822))]
|
||||
[find-seconds ((integer-in 0 61)
|
||||
|
@ -251,6 +252,15 @@
|
|||
(lambda ()
|
||||
(force d))))
|
||||
|
||||
(define (date->seconds date)
|
||||
(find-seconds
|
||||
(date-second date)
|
||||
(date-minute date)
|
||||
(date-hour date)
|
||||
(date-day date)
|
||||
(date-month date)
|
||||
(date-year date)))
|
||||
|
||||
(define (find-seconds sec min hour day month year)
|
||||
(define (signal-error msg)
|
||||
(error 'find-secs (string-append
|
||||
|
|
|
@ -15,7 +15,6 @@ The value of @racket[(current-seconds)] increases as time passes
|
|||
seconds can be compared with a time returned by
|
||||
@racket[file-or-directory-modify-seconds].}
|
||||
|
||||
|
||||
@defproc[(seconds->date [secs-n exact-integer?]) date?]{
|
||||
|
||||
Takes @racket[secs-n], a platform-specific time in seconds returned by
|
||||
|
@ -147,6 +146,10 @@ day only if @racket[time?]. See also @racket[date-display-format].}
|
|||
Parameter that determines the date string format. The initial format
|
||||
is @racket['american].}
|
||||
|
||||
@defproc[(date->seconds [date date?]) exact-integer?]{
|
||||
Finds the representation of a date in platform-specific seconds. If
|
||||
the platform cannot represent the specified date, an error is
|
||||
signaled, otherwise an integer is returned. }
|
||||
|
||||
@defproc[(find-seconds [second (integer-in 0 61)]
|
||||
[minute (integer-in 0 59)]
|
||||
|
|
|
@ -20,11 +20,14 @@
|
|||
(test-find 0 0 0 1 4 2005)
|
||||
|
||||
; date->string
|
||||
(let ([d (seconds->date (find-seconds 1 2 3 4 5 2006))])
|
||||
(let* ([secs (find-seconds 1 2 3 4 5 2006)]
|
||||
[d (seconds->date secs)])
|
||||
(define (test-string fmt time? result)
|
||||
(test (parameterize ([date-display-format fmt])
|
||||
(date->string d time?))
|
||||
fmt result))
|
||||
(test secs date->seconds d)
|
||||
|
||||
(test-string 'american #f "Thursday, May 4th, 2006")
|
||||
(test-string 'american #t "Thursday, May 4th, 2006 3:02:01am")
|
||||
(test-string 'chinese #f "2006/5/4 星期四")
|
||||
|
|
Loading…
Reference in New Issue
Block a user