0

Is this how I can return a time zone string from a function?

(defun timezone (ptz)
    "Gets the Posix Timezone String for major locations."

    (cond
     ((equal ptz "Alaska")
         "ASKT9AKDT,M3.2.0/2:00:00,M11.1.0/2:00:00")
     ((equal ptz "Denver-Colorado")
         "MST7MDT,M3.2.0/2:00:00,M11.1.0/2:00:00")
     ((equal ptz "Argentina")
         "ART3")
     ((equal ptz "Greenland")
         "WGST3WGT,M3.2.0/2:00:00,M11.1.0/2:00:00")))
1
  • Well, what happens when you evaluate it, and then call it?
    – nega
    Commented Dec 6, 2022 at 4:31

1 Answer 1

0

This is absolutely the wrong thing to do. At no point should you ever use strings like "MST7MDT,M3.2.0/2:00:00,M11.1.0/2:00:00" to specify a timezone. Instead, take a standardized name like “America/Denver” and look it up in the time zone database. Emacs will even do that for you; just use the name whenever it wants a ZONE as an argument:

(format-time-string "%FT%T%z" nil "America/Denver")
⇒ "2022-12-05T22:57:51-0700"

(format-time-string "%FT%T%z" nil "Europe/London")
⇒ "2022-12-06T05:57:51+0000"
4
  • So with Emacs I do not need to look up in the time zone database? Just use format-time-string ? But how can I determine the zone for format-time-string?
    – Dilna
    Commented Dec 6, 2022 at 6:20
  • From the time zone database: en.wikipedia.org/wiki/Tz_database#Names_of_time_zones
    – db48x
    Commented Dec 6, 2022 at 6:33
  • What is the nanosecond %N ? Is it based on 60 or is it digital ?
    – Dilna
    Commented Dec 6, 2022 at 6:49
  • %N shows nanoseconds as a 9-digit decimal fraction of a second: (format-time-string "%FT%T.%N%z" nil "Europe/London") ==> "2022-12-06T16:21:19.539641390+0000"
    – NickD
    Commented Dec 6, 2022 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.