2012-04-12 46 views
38

因此,在工作中我们使用flexitime(flex hours,flexi hours ...),这很好,但很难跟踪。我目前使用org-mode来记录我的工作时间(org-clock-(out|in)),但我想扩展到自动计算工作时间是否超过8小时(剩余时间应该添加到我的flexitime帐户中)或更少(取决于我吃了多少午餐时间等等),我的弹性工作“账户”上的余额等等。使用Emacs跟踪flexitime(&org-mode)

其他人使用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'通常表明存在这样的问题。 '而不是当前缓冲区+查找文件+切换到缓冲区,你想使用'(with-current-buffer(find-file-noselect ...)...)'。还有一点需要注意:不要打扰调用'convert-standard-filename',因为它可能并没有真正做到你的想法,而且你的代码在没有它的情况下也能正常工作。 – Stefan 2012-09-07 14:21:44

回答

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当你在钟表来重新生成。

您可以通过使用另一个公式计算加班总和来获得总加班费。但是,我没有解决这个问题。

+0

我一定会尝试一下。 – 2012-10-08 08:21:41

+0

嗨!我现在很晚参加派对,但是谢谢你!最后一个问题,如果我稍后弥补,我可以工作不到8小时。上面的代码导致我的加班时间(我不得不删除'(if)'语句)可以是'-1:-1'(工作6:59之后)。我从'(org-minutes-to-hh:mm-string)'看了定义,但是不知道该怎么做。 – monotux 2013-01-15 07:56:43

+0

我最终弄明白了。谢谢! – monotux 2013-03-17 07:44:04