From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: parsing time strings from properties Date: Sun, 22 Sep 2019 13:18:36 -0400 Message-ID: References: <23943.18598.271616.396497@AGAME7.local> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000dbbf20593277ff8" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:58849) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iC5Va-0007Aa-OR for emacs-orgmode@gnu.org; Sun, 22 Sep 2019 13:18:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iC5VZ-0001Ee-IC for emacs-orgmode@gnu.org; Sun, 22 Sep 2019 13:18:50 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:42323) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iC5VZ-0001EB-BJ for emacs-orgmode@gnu.org; Sun, 22 Sep 2019 13:18:49 -0400 Received: by mail-pg1-x530.google.com with SMTP id z12so6520975pgp.9 for ; Sun, 22 Sep 2019 10:18:49 -0700 (PDT) In-Reply-To: <23943.18598.271616.396497@AGAME7.local> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Thomas Plass Cc: Org Mode --0000000000000dbbf20593277ff8 Content-Type: text/plain; charset="UTF-8" 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 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 > --0000000000000dbbf20593277ff8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
many thanks to both of you. Yours was very interestin= g to read, Thomas, but ts makes it quite a bit easier to write:
<= br>
(defun o-l-date-to-timestamp (date)
=C2=A0 "use ts.el= date parse functions return an ISO-compatible
timestamp for transmissio= n to Canvas via API. DATE is a string,
usually of the form `2019-09-26`,= but optionally including a full time."

=C2=A0 (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 s= implify my often very obtuse legacy code.=C2=A0


On= Sun, Sep 22, 2019 at 6:10 AM Thomas Plass <thunk2@arcor.de> 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 cou= rse is taught in -- from
: emacs, and construct the string from that value.=C2=A0

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)
=C2=A0 (let* ((ymd (mapcar (lambda (s) (string-to-number s)) (split-string = y-m-d "-")))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(offsecs (nth 8
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(decode-time
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (apply #'encode-time
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(list 59 59 23 (nth 2 ymd) (nth 1 ymd= ) (nth 0 ymd)))))))
=C2=A0 =C2=A0 (format "%s%02d:%02d"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (> offsecs 0) "+"= ; "-")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (/ offsecs 3600)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (% offsecs 3600))))

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

Thomas
--0000000000000dbbf20593277ff8--