emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] parsing time strings from properties


From: Matt Price
Subject: Re: [O] parsing time strings from properties
Date: Sun, 22 Sep 2019 13:18:36 -0400

many thanks to both of you. Yours was very interesting to read, Thomas, but ts makes it quite a bit easier to write:

(defun o-l-date-to-timestamp (date)
  "use ts.el date parse functions return an ISO-compatible
timestamp for transmission to Canvas via API. DATE is a string,
usually of the form `2019-09-26`, but optionally including a full time."

  (ts-format "%Y-%m-%dT%H:%M:%S%:z" (ts-parse-fill 'end date )))

I'm quite looking forward to using dash, s, ts, kv, etc to simplify my often very obtuse legacy code. 


On Sun, Sep 22, 2019 at 6:10 AM Thomas Plass <address@hidden> wrote:
Hi,

Matt Price wrote at 16:27 on September 21, 2019:
:
: :DUE_AT: 2019-09-26
:
: ...
:
: I'm wondering though how hard
: it would be to get the current time zone -- or the time zone that the course is taught in -- from
: emacs, and construct the string from that value. 

This'll return the offset suffix (if that's what you want) when
executed in your local time zone (presumably "-04:00"):

(defun Price/local-time-offset-from-iso-date (y-m-d)
  (let* ((ymd (mapcar (lambda (s) (string-to-number s)) (split-string y-m-d "-")))
         (offsecs (nth 8
                       (decode-time
                        (apply #'encode-time
                               (list 59 59 23 (nth 2 ymd) (nth 1 ymd) (nth 0 ymd)))))))
    (format "%s%02d:%02d"
            (if (> offsecs 0) "+" "-")
            (/ offsecs 3600)
            (% offsecs 3600))))

On Unix, this'll always work.  On Windows, it works most of the time,
but may fail in the weeks around switches from and to daylight saving.

Thomas

reply via email to

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