emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-habit and hourly repeats
@ 2023-01-18  6:38 Felipe Balbi
  2023-01-19 10:48 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Felipe Balbi @ 2023-01-18  6:38 UTC (permalink / raw)
  To: emacs-orgmode


Hi,

I'm trying to start using `org-habit' but I noticed that hourly repeats
are not properly parsed by `org-habit-duration-to-days', however that's
a valid use case --- e.g. drinking water, medicine schedule,
physiotherapy sessions during the day, periodically practicing a new
language. For example, here's an easy TODO item that reproduces the
problem:

8< -------------------- cut here --------------------

* TODO Foo
  SCHEDULED: <2023-01-18 Wed 11:00 .+8h>
  :PROPERTIES:
  :STYLE:    habit
  :END:

8< -------------------- cut here --------------------

It appears that a simple solution would be modify
`org-habit-duration-to-days' to accept the `h' suffix and set it to a
fraction of a day, something like:

8< -------------------- cut here --------------------

(defun org-habit-duration-to-days (ts)
  (if (string-match "\\([0-9]+\\)\\([hdwmy]\\)" ts)
      ;; lead time is specified.
      (floor (* (string-to-number (match-string 1 ts))
		(cdr (assoc (match-string 2 ts)
			    '(("h" . 0.042) ("d" . 1)
                              ("w" . 7)     ("m" . 30.4)
                              ("y" . 365.25))))))
    (error "Invalid duration string: %s" ts)))

8< -------------------- cut here --------------------

Would something like this be an acceptable solution?

-- 
balbi


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

end of thread, other threads:[~2023-01-19 11:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-18  6:38 org-habit and hourly repeats Felipe Balbi
2023-01-19 10:48 ` Ihor Radchenko
2023-01-19 10:58   ` Felipe Balbi
2023-01-19 11:04     ` Ihor Radchenko
2023-01-19 11:06       ` Felipe Balbi
2023-01-19 11:13         ` Ihor Radchenko

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