[plt-scheme] GMT date stamps and time-zone-offset

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Aug 19 13:16:08 EDT 2007

Hi all,

The function seconds->date-string below is supposed to
return a data stamp using GMT. At first I thought I
were to adjust for summer time, but it seems that
happens automatically. But to be on the safe side, I'd
appreciate, if you try running the snippet below. The
correct GMT time can be seen at:

     http://wwp.greenwichmeantime.com/

/Jens Axel


; pad : string integer -> string
;   prefix the string s with 0 until the length is at least n
(define (pad s n)
   (let ([s (format "~a" s)])
     (if (< (string-length s) n)
         (pad (string-append "0" s) n)
         s)))

; seconds->date-string : [integer] -> string
;   return string representing the date given by either
;   the given seconds or the result of (current-seconds)
(define seconds->date-string
   (case-lambda
     [()
      (seconds->date-string (current-seconds))]
     [(seconds)
      (let* ([d (seconds->date seconds)]
             [seconds (- seconds
                         0
                         ; adjust timezone
                         (date-time-zone-offset d)
                         ; adjust summer time
                         #;(if (date-dst? d) (- (* 60 60)) 0))]
             [d (seconds->date seconds)])
        (format "~a, ~a ~a ~a ~a:~a:~a GMT"
                (vector-ref '#("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat")
                            (date-week-day d))
                (pad (date-day d) 2)
                (vector-ref '#("Jan" "Feb" "Mar" "Apr" "May" "Jun"
                               "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")
                            (- (date-month d) 1))
                (date-year d)
                (pad (date-hour d) 2)
                (pad (date-minute d) 2)
                (pad (date-second d) 2)))]))

(seconds->date-string)



Posted on the users mailing list.