0

I'm trying to set org-duration-units that's used by org-mode effort estimates for formatting times in 8 hour days instead of 24 hours days.

I'm in no way an emacs and lisp expert, currently learning as I go along. I tried this in my ~/.emacs file:

(use-package org
  :mode (("\\.org$" . org-mode))
  :ensure org-plus-contrib
  :custom
   (org-duration-units   `(("min" . 1)
   ("h" . 60)
   ("d" . ,(* 60 8))
   ("w" . ,(* 60 8 5))
   ("m" . ,(* 60 8 5 4))
   ("y" . ,(* 60 8 5 4 11)))
  )
  :config
    (setq org-clock-persist 'history)
    (org-clock-persistence-insinuate)
    (setq org-clock-idle-time 15)
    (setq org-duration-format 'h:mm)

 ;; also tried to set it in the config block instead to be executed after load
 ;; (setq org-duration-units   `(("min" . 1)
 ;;                               ("h" . 60)
 ;;                               ("d" . ,(* 60 8))
 ;;                               ("w" . ,(* 60 8 5))
 ;;                               ("m" . ,(* 60 8 5 4))
 ;;                               ("y" . ,(* 60 8 5 4 11))))
 ;;  (org-duration-set-regexps)

    )

I then try to use org-duration-from-minutes in some code displaying a table to convert a duration to some nicely formatted times with 8 hour days. Here is a minimum org-mode example:

#+BEGIN_SRC emacs-lisp

;; six month of 4 weeks of 5 days of 8 hours per day (120 days of 8 hours)
;; expecting 6m 00:00
;; or 40 days of 24 hours

(print (org-duration-from-minutes 57600 ))
#+END_SRC

#+RESULTS:
: 40d 0:00

It shows it in 24h days format. When I run

(setq org-duration-units `(("min" . 1) ("h" . 60) ("d" . ,(* 60 8)) ("w" . ,(* 60 8 5)) ("m" . ,(* 60 8 5 4)) ("y" . ,(* 60 8 5 4 10))) )

Then it shows it as 120d 0:00

How do I get emacs to set org-duration-units at startup ? It looks like it's either not set or overridden in the way I do it.

migrated from superuser.com Jun 19 at 12:19

This question came from our site for computer enthusiasts and power users.

0

Emacs version: 26.1
org-version: 9.1.13

You are customizing for the wrong package.

Use package org-duration instead of org for org-duration-units:

(use-package org
  :mode (("\\.org$" . org-mode))
  :ensure org-plus-contrib
  :config
    (setq org-clock-persist 'history)
    (org-clock-persistence-insinuate)
    (setq org-clock-idle-time 15)
    (setq org-duration-format 'h:mm))

(use-package org-duration
  :config
  (setq org-duration-units   `(("min" . 1)
   ("h" . 60)
   ("d" . ,(* 60 8))
   ("w" . ,(* 60 8 5))
   ("m" . ,(* 60 8 5 4))
   ("y" . ,(* 60 8 5 4 11))))
  (org-duration-set-regexps))

It does not help if you execute code after loading org since org-duration is loaded per autoload afterwards.


Using :custom gives pitingly wrong results if the use-package form is executed only once.

The reason is that customize-set-variable is executed before org-duration is loaded. (The order of loading the package and executing the :custom forms is not defined in the use-page. Even so I consider that almost a bug.)

But, you can use customize-set-variable in :config to get the wanted effect:

(use-package org-duration
    :config
    (customize-set-variable
     'org-duration-units
     `(("min" . 1)
       ("h" . 60)
       ("d" . ,(* 60 8))
       ("w" . ,(* 60 8 5))
       ("m" . ,(* 60 8 5 4))
       ("y" . ,(* 60 8 5 4 11)))))
  • Thanks @Tobias, I didn't realise it was in another package. Could it also be set with the :custom command ? From what I understand, this might be a more canonical way which automatically calls org-duration-set-regexps? – nab Jun 20 at 10:29
  • @nab I added a remark on :custom. – Tobias Jun 20 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.