;; Orgmode (require 'org) (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) (setq org-agenda-files (file-expand-wildcards "~/org/*.org")) (setq org-export-docbook-xslt-stylesheet "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl") (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i") (setq org-export-docbook-xsl-fo-proc-command "fop %i %o") (setq org-time-clocksum-format '(:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t)) ;; Org-mode daily reports (defun tstr (timeval) "Format date to string" (format-time-string (car org-time-stamp-formats) timeval)) (defun hmstr (timeval) "Format date to string" (format-time-string "%H:%M" timeval)) (defun timeuniq (timelist) (defun dup (ts timelist) (cond ((not timelist) nil) ((equal ts (car timelist)) t) (t (dup ts (cdr timelist))))) (defun tcheck (timelist duplist) (cond ((not timelist) nil) ((dup (car timelist) (cdr timelist)) (tcheck (cdr timelist) (cons (car timelist) duplist))) ((dup (car timelist) duplist) (tcheck (cdr timelist) duplist)) (t (cons (car timelist) (tcheck (cdr timelist) duplist))))) (tcheck timelist ())) (defun org-clock-seb (&optional tstart tend) (interactive) (org-with-silent-modifications (let* ((re (concat "^[ \t]*" org-clock-string "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ \t]+\\([0-9]+\\):\\([0-9]+\\)\\)")) ts te tl) (if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart))) (if (stringp tend) (setq tend (org-time-string-to-seconds tend))) (if (consp tstart) (setq tstart (org-float-time tstart))) (if (consp tend) (setq tend (org-float-time tend))) (save-excursion (goto-char (point-max)) (while (re-search-backward re nil t) (cond ((match-end 1) ;; Two time stamps (setq ts (match-string 1) te (match-string 2) ts (org-float-time (apply 'encode-time (org-parse-time-string ts))) te (org-float-time (apply 'encode-time (org-parse-time-string te))) ts (if tstart (max ts tstart) ts) te (if tend (min te tend) te) tl (if (> (- te ts) 0) (append (list ts te) tl)))))) (timeuniq (sort tl '<)))))) (defun org-dblock-write:rangereport (params) "Display day-by-day time reports." (let* ((ts (plist-get params :tstart)) (te (plist-get params :tend)) (block (plist-get params :block)) (ws (plist-get params :wstart)) (ms (plist-get params :mstart)) cc range-text) (org-clock-sum 0 1) (when block (setq cc (org-clock-special-range block nil t ws ms) ts (car cc) te (nth 1 cc) range-text (nth 2 cc))) (setq ts (org-time-string-to-time ts)) (setq te (org-time-string-to-time te)) (defun add-day (timeval) "Add a day to the date" (setq curr (decode-time timeval)) (setcar (nthcdr 3 curr) (+ (nth 3 curr) 1)) (apply 'encode-time (butlast curr 3))) (unless range-text (setq range-text (concat "[" (tstr ts) " - " (tstr te) "]"))) (insert "Time report " range-text "\n") (setq totalmin 0) (while (time-less-p ts te) (setq nday (add-day ts)) (org-clock-sum (time-to-seconds ts) (time-to-seconds nday)) (setq seb (org-clock-seb (time-to-seconds ts) (time-to-seconds nday))) (setq minutes org-clock-file-total-minutes) (setq totalmin (+ minutes totalmin)) (setq tt (org-minutes-to-clocksum-string minutes)) (if (not (string= "0:00" tt)) (progn (setq seb (append (cons (car seb) (last seb)) (butlast (cdr seb)))) (setq sebstr (mapcar 'hmstr (mapcar 'seconds-to-time seb))) (setq timestr (format "%s [s %5s e %5s %15s] [%5s (%0.2f)]\n" (tstr ts) (car sebstr) (car (cdr sebstr)) (cdr (cdr sebstr)) tt (/ minutes 60.0))) (insert timestr))) (setq ts nday ) ) (insert "Total time : " (org-minutes-to-clocksum-string totalmin)"\n") (insert "Total mins : " (format "%f" totalmin) "\n") (insert "Total days : " (format "%f" (/ totalmin (* 7.7 60.0)))) ))