emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Peder Stray <peder.stray@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Patch to get clocktable to split on week boundraries
Date: Mon, 4 Mar 2013 15:44:24 +0100	[thread overview]
Message-ID: <CAE4U0JGxbaF4e=MDPeRA-5=49bsz4_z-e=noqEZ2Sem6e5CJ3g@mail.gmail.com> (raw)

[-- Attachment #1.1: Type: text/plain, Size: 412 bytes --]

When calling clocktable with :block *month and :step week it splits into
block 7 days long starting from the first day in the month... that's not
very useful I think, so here is a patch making it split the month into
weeks starting on mondays.  The first and last week will be clipped to only
include the days in the selected month and as such will not contain the
full 7 days of those weeks.

  Peder Stray

[-- Attachment #1.2: Type: text/html, Size: 476 bytes --]

[-- Attachment #2: org-clock-clocktable-weekstart-2.patch --]
[-- Type: application/octet-stream, Size: 1427 bytes --]

--- org-clock.el.week	2013-02-20 13:36:02.465813986 +0100
+++ org-clock.el	2013-03-04 09:28:49.436080295 +0100
@@ -2518,7 +2518,7 @@
 	 (step (cdr (assoc step0 '((day . 86400) (week . 604800)))))
 	 (stepskip0 (plist-get p1 :stepskip0))
 	 (block (plist-get p1 :block))
-	 cc range-text step-time)
+	 cc range-text step-time tsb)
     (when block
       (setq cc (org-clock-special-range block nil t)
 	    ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
@@ -2538,17 +2538,21 @@
       (setq te (org-float-time
 		(apply 'encode-time (org-parse-time-string te))))))
+    (setq tsb 
+	  (if (eq step0 'week) 
+	      (- ts (* 86400 (- (nth 6 (decode-time (seconds-to-time ts))) 1)))
+	    ts))
     (setq p1 (plist-put p1 :header ""))
     (setq p1 (plist-put p1 :step nil))
     (setq p1 (plist-put p1 :block nil))
-    (while (< ts te)
+    (while (< tsb te)
       (or (bolp) (insert "\n"))
       (setq p1 (plist-put p1 :tstart (format-time-string
 				      (org-time-stamp-format nil t)
-				      (seconds-to-time ts))))
+				      (seconds-to-time (max ts tsb)))))
       (setq p1 (plist-put p1 :tend (format-time-string
 				    (org-time-stamp-format nil t)
-				    (seconds-to-time (setq ts (+ ts step))))))
+				    (seconds-to-time (min te (setq tsb (+ tsb step)))))))
       (insert "\n" (if (eq step0 'day) "Daily report: "
 		     "Weekly report starting on: ")
 	      (plist-get p1 :tstart) "\n")

             reply	other threads:[~2013-03-04 14:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-04 14:44 Peder Stray [this message]
2013-03-15 10:50 ` Patch to get clocktable to split on week boundraries Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE4U0JGxbaF4e=MDPeRA-5=49bsz4_z-e=noqEZ2Sem6e5CJ3g@mail.gmail.com' \
    --to=peder.stray@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).