emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* parsing time strings from properties
@ 2019-09-21 20:27 Matt Price
  2019-09-22  2:54 ` Adam Porter
  2019-09-22 10:10 ` Thomas Plass
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Price @ 2019-09-21 20:27 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1290 bytes --]

I use a very simple property in my assignment descriptions to set the
assignment due date:

:DUE_AT: 2019-09-26

I then pass this to an API which expects a date parameter like
`2019-09-26T23:59:59-04:00`. Since I only work in one time zone, I  can
just concat the property value with the additional text, though actually I
have to change the `-04:00` string twice a year.  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.

Basically, I want a simple date representation to be interpreted as "the
last possible moment on this date i nthe appropriate time zone". I have not
tried to use timestamps here, in part because I'm more comfortable dealing
with text than with the horrors of time representations in either lisp or
javascript. Alsoi, I find it very very fast to insert a  text string, and
just a little bit slower and more of an interruption to add a timestamp.  I
just wanted to ask how other people manage this kind of operation; maybe I
should make the effort to start using DEADLINE timestamps. I don't really
use them in my own time management so I'm not well-versed in how to manage
them.

In nay case, I as always appreciate all of your help.

Matt

[-- Attachment #2: Type: text/html, Size: 1491 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parsing time strings from properties
  2019-09-21 20:27 parsing time strings from properties Matt Price
@ 2019-09-22  2:54 ` Adam Porter
  2019-09-22 10:10 ` Thomas Plass
  1 sibling, 0 replies; 4+ messages in thread
From: Adam Porter @ 2019-09-22  2:54 UTC (permalink / raw)
  To: emacs-orgmode

For parsing timestamps, you may find this helpful:

https://github.com/alphapapa/ts.el

See e.g. functions ts-parse-org and ts-parse-org-fill.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parsing time strings from properties
  2019-09-21 20:27 parsing time strings from properties Matt Price
  2019-09-22  2:54 ` Adam Porter
@ 2019-09-22 10:10 ` Thomas Plass
  2019-09-22 17:18   ` Matt Price
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Plass @ 2019-09-22 10:10 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parsing time strings from properties
  2019-09-22 10:10 ` Thomas Plass
@ 2019-09-22 17:18   ` Matt Price
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Price @ 2019-09-22 17:18 UTC (permalink / raw)
  To: Thomas Plass; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]

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 <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
> 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
>

[-- Attachment #2: Type: text/html, Size: 2285 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-22 17:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-21 20:27 parsing time strings from properties Matt Price
2019-09-22  2:54 ` Adam Porter
2019-09-22 10:10 ` Thomas Plass
2019-09-22 17:18   ` Matt Price

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).