emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Patch to get clocktable to split on week boundraries
@ 2013-03-04 14:44 Peder Stray
  2013-03-15 10:50 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Peder Stray @ 2013-03-04 14:44 UTC (permalink / raw)
  To: emacs-orgmode


[-- 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 @@
      (te
       (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")

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Patch to get clocktable to split on week boundraries
  2013-03-04 14:44 Patch to get clocktable to split on week boundraries Peder Stray
@ 2013-03-15 10:50 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2013-03-15 10:50 UTC (permalink / raw)
  To: Peder Stray; +Cc: emacs-orgmode

Hi Peder,

Peder Stray <peder.stray@gmail.com> writes:

> 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.

thanks for this idea and for the patch.  I just pushed a different
implementation, allowing a new :mstart parameter for clocktables,
similar to the already existing :wstart parameter.

The default for :wstart (the week starting day) is 1, for monday.
The default for :mstart (the month starting day) is 1, for the first
day of the month.

So the new default for e.g.,

  #+BEGIN: clocktable :block month :step week
  #+END

is to start on the 1st of the month (ignoring :wstart) and to continue
with weeks starting on mondays.

If you use

  #+BEGIN: clocktable :block month :step week :wstart 2 :mstart 3
  #+END

it will start the report on the 3rd of the month, and continue the
weekly steps starting from tuesdays.

Thanks for this idea and for the patch!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-15 10:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04 14:44 Patch to get clocktable to split on week boundraries Peder Stray
2013-03-15 10:50 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).