2

I use org-mode to do time registration. Is there a way to round time register using clock-in / clock-out up to a multiple of a user defined value for instance 5 mins when generating a org-clock-table report?

7
  • You can round when clocking in or alternatively, when adjusting times with a key combination.
    – wasamasa
    Oct 18, 2017 at 17:47
  • Thanks, but I am looking for an automatic solution.
    – mac
    Oct 18, 2017 at 19:08
  • How is the former not one?
    – wasamasa
    Oct 18, 2017 at 22:12
  • Sorry, then I simply don't understand what you mean by "round when clocking in".
    – mac
    Oct 19, 2017 at 5:35
  • See org-clock-rounding-minutes.
    – wasamasa
    Oct 19, 2017 at 5:52

1 Answer 1

5
+50

I had to do something similar at work and I solved it by calling the clocktable with a (calc) formula:

#+BEGIN: clocktable :maxlevel 3 :block 2017-10-24 :formula "$2=$3;t::$3=if($2 == 0, string(\"\"), round(100*ceil($2*12)/12)/100)"
#+END:

Short explanation:

  • Depending on your use of levels (maxlevels) you might need to change the column numbers.
  • I usually create a clocktable per day. :block 2017-10-24 would be for today.
  • Since the clocktable usually contains the clocked time in the format 0:00 which is not as easy to calculate with, I use the t flag to display the values in decimal numbers. This requires org-table-duration-custom-format to be set to the default 'hours (see here).
  • Then I use some calc formulas: ceil is used to round up to the next full 5 minutes. If you prefer to go to the nearest 5 minute unit (round up or down), you can replace it with round. The outer formula (round) is then used that the result has only two decimals digits.
  • I use the if clause to check if the result is 0.00 or not. If it is, which means there is no clocked time (in my case on the headers), the cell should be empty.
4
  • I finally had the chance to try this out and it does not work as intended. For a table with :maxlevel 5 what would the the #+BEGIN line have to look like?
    – mac
    Nov 26, 2017 at 1:25
  • I am sorry to hear that. So, you're working with maxlevel 5. The time numbers you want to round are therefore all in the 5th column or are there other times you want to round (and in which column)? In the former case try it with this formula: :formula "$6=5;t::$7=if($6 == 0, string(\"\"), round(100*ceil($6*12)/12)/100)". This should create a new 6th column in which the numbers from the 5th column are converted to decimals and a new 7th column where the rounding happens.
    – Fabian
    Nov 27, 2017 at 5:58
  • The numbers that need to be rounded are in all cols expect the total. Problem is that numbers in col 4 are already the addition of col 5 and col 4. I think I need to format the initial clock-table differently to achieve what I want, but I don't know how.
    – mac
    Nov 27, 2017 at 9:46
  • How about you use a different maxlevel (e.g. 3 like in my answer)? This already formats the clock-table differently. Or how about you give me an (anonymized) example of how your clock-table looks like before any formula was applied to it and tell me which numbers you would like to be rounded.
    – Fabian
    Dec 30, 2017 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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