chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] time->string


From: Zbigniew
Subject: Re: [Chicken-hackers] time->string
Date: Sat, 19 Jan 2008 13:56:49 -0600

On Jan 19, 2008 12:59 PM, John Cowan <address@hidden> wrote:

> Instead, I suggest making time->string return an ISO 8601 time string of
> the form "yyyy-mm-ddThh:mm:ss+zzzz"

Well, ISO 8601 time strings are already available in SRFI-19, and
they're not particularly readable.  And all the components you need
(including timezone) for that are already included in the 10-element
vector you pass to time->string.  If you don't want to include srfi-19
here's a dumb time->iso8601-string (disclaimer, barely tested):

(define (time->iso8601-string vec)
  (let ((v (lambda (n) (vector-ref vec n)))
        (p (lambda (n) (conc (if (< n 10) "0" "")
                        (number->string n)))))
    (conc (+ 1900 (v 5)) "-" (p (add1 (v 4))) "-" (p (add1 (v 3)))
          "T" (p (v 2)) ":" (p (v 1)) ":" (p (v 0))
          (if (> (v 9) 0) "-" "+")
          (p (quotient (v 9) 3600))
          (p (remainder (v 9) 3600)))))

#;90> (time->iso8601-string (seconds->local-time (current-seconds)))
"2008-01-20T13:52:07-0600"
#;91> (time->iso8601-string (seconds->utc-time (current-seconds)))
"2008-01-20T19:52:14+0000"

Or you could add the missing timezone yourself:

(string-append
 (time->string (seconds->local-time (current-seconds)))
 " " (local-timezone-abbreviation))

; => "Sat Jan 19 13:27:00 2008 CST"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]