使用Emacs (& org-mode)跟踪弹性工作时间

38

因此,在工作中我们使用弹性工作时间(弹性工时,弹性时间...),这很不错,但可能难以跟踪。我目前正在使用org-mode来记录我的工时(org-clock-(out|in)),但我希望将其扩展到自动计算我是否工作超过8小时(多余的时间应添加到我的弹性工作时间“账户”中)或者更少(根据我休息的午餐时间等),我的弹性工作时间“账户”的余额等。

还有其他人使用Emacs来实现这个功能吗?

我目前正在使用一个非常基本的设置来跟踪我的时间:

(defun check-in ()
  (interactive)
  (let (pbuf (current-buffer))
    (find-file (convert-standard-filename "whatnot"))
    (goto-char (point-max))
    (insert "\n")
    (org-insert-heading)
    (org-insert-time-stamp (current-time))
    (org-clock-in)
    (save-buffer)
    (switch-to-buffer pbuf)))

(defun check-out ()
  (interactive)
  (let (pbuf (current-buffer))
    (find-file (convert-standard-filename "whatnot"))
    (goto-char (point-max))
    (org-clock-out)
    (save-buffer)
    (switch-to-buffer pbuf)))

2
你的代码混淆了current-buffer和在selected-window中显示的缓冲区。从Elisp调用switch-to-buffer通常是这些问题的信号。与其使用current-buffer+find-file+switch-to-buffer,你应该使用(with-current-buffer (find-file-noselect ...) ...)。还有一点:不必打扰调用convert-standard-filename,因为它很可能不会真正做你想要的事情,而且没有它你的代码也能正常工作。 - Stefan
1个回答

4

假设我正确理解了你的问题,我快速地想出了一个解决方案。首先,如果你要多次签到和签退,请确保每天只创建一个大纲条目。定义以下函数来计算给定日期的加班时间。

(defun compute-overtime (duration-string)
  "Computes overtime duration string for the given time DURATION-STRING."
  (let (minutes-in-a-workday
        work-minutes
        overtime-minutes)
    (defconst minutes-in-a-workday 480)
    (setq work-minutes (org-duration-string-to-minutes duration-string)
          overtime-minutes (- work-minutes minutes-in-a-workday))
    (if (< overtime-minutes 0) (setq overtime-minutes 0))
    (org-minutes-to-hh:mm-string overtime-minutes)))

然后,在文件whatnot中使用这个公式来创建一个时钟表格。
#+BEGIN: clocktable :maxlevel 1 :emphasize nil :scope file :formula "$3='(compute-overtime $2)::@2$3=string(\"Overtime\")"    
#+END: clocktable

当你在时钟表上时,按下C-c C-c重新生成它。

您可以使用另一个公式对加班时间总和进行求和。但是,我尚未解决这个问题。


我一定会尽快试一试。 - Nikana Reklawyks
嗨!我现在来参加派对有点晚了,但还是谢谢你!最后一个问题,如果我之后补回来的话,我可以工作少于8个小时。上面的代码会导致我的加班天数变成-1:-1(我不得不删除(if)语句)。我查看了(org-minutes-to-hh:mm-string)的定义,但是无法弄清楚如何做到这一点。 - monotux
我最终弄明白了。谢谢! - monotux

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接