reddit / emacs

Elisp Help/Feedback Wanted: Scheduling posts via org-read-date in Mastodon.el

divinedominion 路 2022-11-26 17:56
The "schedule" API of Mastodon is super simple. But I'm not quite sure how to best handle the input 馃 The discussion is here: https://codeberg.org/martianh/mastodon.el/issues/285 In short, the following works, but the fallback value of 12:00 a.m. feels like a hack: (require 'org) (require 'mastodon) (defun ct/mastodon-toot--schedule () (interactive) (let* ((time-value (org-read-date nil t nil "Schedule post at:" (date-to-time "2022-11-26 00:00 am"))) (iso8601-string (format-time-string "%Y-%m-%dT%H:%M:%S%z" time-value))) (setq-local mastodon-toot--scheduled-at iso8601-string) (message (format "Scheduled post for '%s'." iso8601-string)))) (define-key mastodon-toot-mode-map (kbd "C-c C-s") #'ct/mastodon-toot--schedule) `org-read-date` works flawlessly otherwise. How'd you approach this? Feedback and discussion (and PRs on codeberg.org :)) welcome!
yantar92 路 2022-11-26 23:14
1. `(org-read-date t t)` with non-nil first argument WITH-TIME 2. `org-overriding-default-time`
divinedominion 路 2022-11-28 09:20
(2) is interesting, that can work with local bindings! Thanks! The UX of (1) is a bit too restrictive because users are allowed to just specify a date. My function does a bad job representing this, actually, and appends the time to get _a_ complete ISO representation. It'd be better to just return _either_ `"2022-11-28"` _or_ `"2022-11-28T10:19:00+0100"` 馃
yantar92 路 2022-11-28 11:05
> because users are allowed to just specify a date. Time is also allowed
divinedominion 路 2022-12-03 08:07
Yes: not "just allowed to specify date" (requirement), but "allowed to just specify a date" (option) 馃憤 :)
divinedominion 路 2022-12-03 10:00
`org-overriding-default-time` is just another way to specify the whole list of time-and-date. I think my approach isn't working.
divinedominion 路 2022-12-03 10:02
A better approach might actually be this: (let* ((org-time-string (with-temp-buffer (call-interactively #'org-time-stamp) (buffer-substring-no-properties (point-min) (point-max)))) (time-value (org-parse-time-string org-time-string))) (message "%s" (format-time-string "%Y-%m-%dT%H:%M:%S%:z" (encode-time time-value)))) `org-time-stamp` produces either date-and-time like `<2022-12-03 Sat 10:42>` or just date like `<2022-12-03 Sat>`. It contains all the logic to drop the time when the user doesn't specify it. Since the internal time structures don't support optional times, treating this string format as canonical might be better.