Re: [Orgmode] [PATCH] Quarters added to clocktables

2010-11-29 Thread Erwin Vrolijk

Hi Carsten,

Thank you for your feedback. The FSF papers are no problem, i've already 
got them by mail.

Here are the new patches, patched to the current HEAD.

Regards,
Erwin Vrolijk
Snow B.V.

diff --git a/doc/org.texi b/doc/org.texi
index 17d6e65..a4073d0 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -5820,6 +5820,7 @@ be selected:
 2007-12-31@r{New year eve 2007}
 2007-12   @r{December 2007}
 2007-W50  @r{ISO-week 50 in 2007}
+ 2007-Q2   @r{2nd quarter in 2007}
 2007  @r{the year 2007}
 today, yesterday, tod...@var{n}  @r{a relative day}
 thisweek, lastweek, thiswe...@var{n} @r{a relative week}

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index e798027..a7c4a97 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1654,6 +1654,65 @@ buffer and update it.
   (= (match-end 0) pos)
   start

+(defun org-day-of-week (day month year)
+  Returns the day of the week as an integer.
+  (nth 6
+   (decode-time
+(date-to-time
+ (format %d-%02d-%02dT00:00:00 year month day)
+
+(defun org-quarter-to-date (quarter year)
+  Get the date (week day year) of the first day of a given quarter.
+  (cond
+   ((= quarter 1)
+(setq startday (org-day-of-week 1 1 year))
+(cond
+ ((= startday 0)
+  (list 52 7 (- year 1)))
+ ((= startday 6)
+  (list 52 6 (- year 1)))
+ ((= startday 4)
+  (list 1 startday year))
+ (( startday 4)
+  (list 53 startday (- year 1)))
+ )
+)
+   ((= quarter 2)
+(setq startday (org-day-of-week 1 4 year))
+(cond
+ ((= startday 0)
+  (list 13 startday year))
+ (( startday 4)
+  (list 14 startday year))
+ ((= startday 4)
+  (list 13 startday year))
+ )
+)
+   ((= quarter 3)
+(setq startday (org-day-of-week 1 7 year))
+(cond
+ ((= startday 0)
+  (list 26 startday year))
+ (( startday 4)
+  (list 27 startday year))
+ ((= startday 4)
+  (list 26 startday year))
+ )
+)
+   ((= quarter 4)
+(setq startday (org-day-of-week 1 10 year))
+(cond
+ ((= startday 0)
+  (list 39 startday year))
+ ((= startday 4)
+  (list 40 startday year))
+ (( startday 4)
+  (list 39 startday year))
+ )
+)
+   )
+  )
+
(defun org-clock-special-range (key optional time as-strings)
  Return two times bordering a special time range.
Key is a symbol specifying the range and can be one of `today', 
`yesterday',

@@ -1670,6 +1729,10 @@ the returned times will be formatted strings.
 (dow (nth 6 tm))
 (skey (symbol-name key))
 (shift 0)
+ (q (cond ((= (nth 4 tm) 10) 4)
+  ((= (nth 4 tm) 7) 3)
+  ((= (nth 4 tm) 4) 2)
+  ((= (nth 4 tm) 1) 1)))
 s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
(cond
 ((string-match ^[0-9]+$ skey)
@@ -1687,6 +1750,15 @@ the returned times will be formatted strings.
  (setq d (nth 1 date) month (car date) y (nth 2 date)
dow 1
key 'week))
+  ((string-match ^\\([0-9]+\\)-[qQ]\\([1-4]\\)$ skey)
+   (require 'cal-iso)
+   (setq y (string-to-number (match-string 1 skey)))
+   (setq q (string-to-number (match-string 2 skey)))
+   (setq date (calendar-gregorian-from-absolute
+   (calendar-absolute-from-iso (org-quarter-to-date q y
+   (setq d (nth 1 date) month (car date) y (nth 2 date)
+dow 1
+key 'quarter))
 ((string-match 
^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$ skey)

  (setq y (string-to-number (match-string 1 skey))
month (string-to-number (match-string 2 skey))
@@ -1694,12 +1766,17 @@ the returned times will be formatted strings.
key 'day))
 ((string-match \\([-+][0-9]+\\)$ skey)
  (setq shift (string-to-number (match-string 1 skey))
-key (intern (substring skey 0 (match-beginning 1))
+key (intern (substring skey 0 (match-beginning 1
+   (if(and (memq key '(quarter thisq)) ( shift 0))
+ (error Looking forward with quarters isn't implemented.)
+(
+
(when (= shift 0)
-  (cond ((eq key 'yesterday) (setq key 'today shift -1))
-((eq key 'lastweek)  (setq key 'week  shift -1))
-((eq key 'lastmonth) (setq key 'month shift -1))
-((eq key 'lastyear)  (setq key 'year  shift -1
+   (cond ((eq key 'yesterday) (setq key 'today   shift -1))
+((eq key 'lastweek)  (setq key 'weekshift -1))
+((eq key 'lastmonth) (setq key 'month   shift -1))
+((eq key 'lastyear)  (setq key 'yearshift -1))
+((eq key 'lastq) (setq key 'quarter shift -1
(cond
 ((memq key '(day today))
  (setq d (+ d shift) h 0 m 0 h1 24 m1 0))
@@ -1708,6 +1785,28 @@ the returned times will be formatted strings.
m 0 h 0 d (- d diff) d1 (+ 7 d)))
 ((memq 

Re: [Orgmode] [PATCH] Quarters added to clocktables

2010-11-29 Thread Carsten Dominik

Hi Erwin,

I cannot get the patch to apply, probably because the mailer is  
destroying it.
Can you please put the patch into a file and send it to me as an  
attachment?


Thanks.

- Carsten

On Nov 29, 2010, at 10:22 AM, Erwin Vrolijk wrote:


Hi Carsten,

Thank you for your feedback. The FSF papers are no problem, i've  
already got them by mail.

Here are the new patches, patched to the current HEAD.

Regards,
Erwin Vrolijk
Snow B.V.

diff --git a/doc/org.texi b/doc/org.texi
index 17d6e65..a4073d0 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -5820,6 +5820,7 @@ be selected:
2007-12-31@r{New year eve 2007}
2007-12   @r{December 2007}
2007-W50  @r{ISO-week 50 in 2007}
+ 2007-Q2   @r{2nd quarter in 2007}
2007  @r{the year 2007}
today, yesterday, tod...@var{n}  @r{a relative  
day}
thisweek, lastweek, thiswe...@var{n} @r{a relative  
week}


diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index e798027..a7c4a97 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1654,6 +1654,65 @@ buffer and update it.
  (= (match-end 0) pos)
  start
+(defun org-day-of-week (day month year)
+  Returns the day of the week as an integer.
+  (nth 6
+   (decode-time
+(date-to-time
+ (format %d-%02d-%02dT00:00:00 year month day)
+
+(defun org-quarter-to-date (quarter year)
+  Get the date (week day year) of the first day of a given quarter.
+  (cond
+   ((= quarter 1)
+(setq startday (org-day-of-week 1 1 year))
+(cond
+ ((= startday 0)
+  (list 52 7 (- year 1)))
+ ((= startday 6)
+  (list 52 6 (- year 1)))
+ ((= startday 4)
+  (list 1 startday year))
+ (( startday 4)
+  (list 53 startday (- year 1)))
+ )
+)
+   ((= quarter 2)
+(setq startday (org-day-of-week 1 4 year))
+(cond
+ ((= startday 0)
+  (list 13 startday year))
+ (( startday 4)
+  (list 14 startday year))
+ ((= startday 4)
+  (list 13 startday year))
+ )
+)
+   ((= quarter 3)
+(setq startday (org-day-of-week 1 7 year))
+(cond
+ ((= startday 0)
+  (list 26 startday year))
+ (( startday 4)
+  (list 27 startday year))
+ ((= startday 4)
+  (list 26 startday year))
+ )
+)
+   ((= quarter 4)
+(setq startday (org-day-of-week 1 10 year))
+(cond
+ ((= startday 0)
+  (list 39 startday year))
+ ((= startday 4)
+  (list 40 startday year))
+ (( startday 4)
+  (list 39 startday year))
+ )
+)
+   )
+  )
+
(defun org-clock-special-range (key optional time as-strings)
 Return two times bordering a special time range.
Key is a symbol specifying the range and can be one of `today',  
`yesterday',

@@ -1670,6 +1729,10 @@ the returned times will be formatted strings.
(dow (nth 6 tm))
(skey (symbol-name key))
(shift 0)
+ (q (cond ((= (nth 4 tm) 10) 4)
+  ((= (nth 4 tm) 7) 3)
+  ((= (nth 4 tm) 4) 2)
+  ((= (nth 4 tm) 1) 1)))
s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
   (cond
((string-match ^[0-9]+$ skey)
@@ -1687,6 +1750,15 @@ the returned times will be formatted strings.
 (setq d (nth 1 date) month (car date) y (nth 2 date)
   dow 1
   key 'week))
+  ((string-match ^\\([0-9]+\\)-[qQ]\\([1-4]\\)$ skey)
+   (require 'cal-iso)
+   (setq y (string-to-number (match-string 1 skey)))
+   (setq q (string-to-number (match-string 2 skey)))
+   (setq date (calendar-gregorian-from-absolute
+   (calendar-absolute-from-iso (org-quarter-to-date  
q y

+   (setq d (nth 1 date) month (car date) y (nth 2 date)
+dow 1
+key 'quarter))
((string-match ^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\ 
\{1,2\\}\\)$ skey)

 (setq y (string-to-number (match-string 1 skey))
   month (string-to-number (match-string 2 skey))
@@ -1694,12 +1766,17 @@ the returned times will be formatted strings.
   key 'day))
((string-match \\([-+][0-9]+\\)$ skey)
 (setq shift (string-to-number (match-string 1 skey))
-key (intern (substring skey 0 (match-beginning 1))
+key (intern (substring skey 0 (match-beginning 1
+   (if(and (memq key '(quarter thisq)) ( shift 0))
+ (error Looking forward with quarters isn't implemented.)
+(
+
   (when (= shift 0)
-  (cond ((eq key 'yesterday) (setq key 'today shift -1))
-((eq key 'lastweek)  (setq key 'week  shift -1))
-((eq key 'lastmonth) (setq key 'month shift -1))
-((eq key 'lastyear)  (setq key 'year  shift -1
+   (cond ((eq key 'yesterday) (setq key 'today   shift -1))
+((eq key 'lastweek)  (setq key 'weekshift -1))
+((eq key 'lastmonth) (setq key 'month   shift -1))
+((eq key 'lastyear)  (setq key 'yearshift -1))
+((eq key 'lastq) (setq key 

Re: [Orgmode] [PATCH] Quarters added to clocktables

2010-11-29 Thread Carsten Dominik


On Nov 29, 2010, at 10:22 AM, Erwin Vrolijk wrote:


Hi Carsten,

Thank you for your feedback. The FSF papers are no problem, i've  
already got them by mail.

Here are the new patches, patched to the current HEAD.


Hi Erwin,

I have applied your patches - please make sure that you complete the  
FSF copyright assignment process and keep me up to date on how that is  
going.


Thanks!

- Carsten



Regards,
Erwin Vrolijk
Snow B.V.

diff --git a/doc/org.texi b/doc/org.texi
index 17d6e65..a4073d0 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -5820,6 +5820,7 @@ be selected:
2007-12-31@r{New year eve 2007}
2007-12   @r{December 2007}
2007-W50  @r{ISO-week 50 in 2007}
+ 2007-Q2   @r{2nd quarter in 2007}
2007  @r{the year 2007}
today, yesterday, tod...@var{n}  @r{a relative  
day}
thisweek, lastweek, thiswe...@var{n} @r{a relative  
week}


diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index e798027..a7c4a97 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1654,6 +1654,65 @@ buffer and update it.
  (= (match-end 0) pos)
  start
+(defun org-day-of-week (day month year)
+  Returns the day of the week as an integer.
+  (nth 6
+   (decode-time
+(date-to-time
+ (format %d-%02d-%02dT00:00:00 year month day)
+
+(defun org-quarter-to-date (quarter year)
+  Get the date (week day year) of the first day of a given quarter.
+  (cond
+   ((= quarter 1)
+(setq startday (org-day-of-week 1 1 year))
+(cond
+ ((= startday 0)
+  (list 52 7 (- year 1)))
+ ((= startday 6)
+  (list 52 6 (- year 1)))
+ ((= startday 4)
+  (list 1 startday year))
+ (( startday 4)
+  (list 53 startday (- year 1)))
+ )
+)
+   ((= quarter 2)
+(setq startday (org-day-of-week 1 4 year))
+(cond
+ ((= startday 0)
+  (list 13 startday year))
+ (( startday 4)
+  (list 14 startday year))
+ ((= startday 4)
+  (list 13 startday year))
+ )
+)
+   ((= quarter 3)
+(setq startday (org-day-of-week 1 7 year))
+(cond
+ ((= startday 0)
+  (list 26 startday year))
+ (( startday 4)
+  (list 27 startday year))
+ ((= startday 4)
+  (list 26 startday year))
+ )
+)
+   ((= quarter 4)
+(setq startday (org-day-of-week 1 10 year))
+(cond
+ ((= startday 0)
+  (list 39 startday year))
+ ((= startday 4)
+  (list 40 startday year))
+ (( startday 4)
+  (list 39 startday year))
+ )
+)
+   )
+  )
+
(defun org-clock-special-range (key optional time as-strings)
 Return two times bordering a special time range.
Key is a symbol specifying the range and can be one of `today',  
`yesterday',

@@ -1670,6 +1729,10 @@ the returned times will be formatted strings.
(dow (nth 6 tm))
(skey (symbol-name key))
(shift 0)
+ (q (cond ((= (nth 4 tm) 10) 4)
+  ((= (nth 4 tm) 7) 3)
+  ((= (nth 4 tm) 4) 2)
+  ((= (nth 4 tm) 1) 1)))
s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
   (cond
((string-match ^[0-9]+$ skey)
@@ -1687,6 +1750,15 @@ the returned times will be formatted strings.
 (setq d (nth 1 date) month (car date) y (nth 2 date)
   dow 1
   key 'week))
+  ((string-match ^\\([0-9]+\\)-[qQ]\\([1-4]\\)$ skey)
+   (require 'cal-iso)
+   (setq y (string-to-number (match-string 1 skey)))
+   (setq q (string-to-number (match-string 2 skey)))
+   (setq date (calendar-gregorian-from-absolute
+   (calendar-absolute-from-iso (org-quarter-to-date  
q y

+   (setq d (nth 1 date) month (car date) y (nth 2 date)
+dow 1
+key 'quarter))
((string-match ^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\ 
\{1,2\\}\\)$ skey)

 (setq y (string-to-number (match-string 1 skey))
   month (string-to-number (match-string 2 skey))
@@ -1694,12 +1766,17 @@ the returned times will be formatted strings.
   key 'day))
((string-match \\([-+][0-9]+\\)$ skey)
 (setq shift (string-to-number (match-string 1 skey))
-key (intern (substring skey 0 (match-beginning 1))
+key (intern (substring skey 0 (match-beginning 1
+   (if(and (memq key '(quarter thisq)) ( shift 0))
+ (error Looking forward with quarters isn't implemented.)
+(
+
   (when (= shift 0)
-  (cond ((eq key 'yesterday) (setq key 'today shift -1))
-((eq key 'lastweek)  (setq key 'week  shift -1))
-((eq key 'lastmonth) (setq key 'month shift -1))
-((eq key 'lastyear)  (setq key 'year  shift -1
+   (cond ((eq key 'yesterday) (setq key 'today   shift -1))
+((eq key 'lastweek)  (setq key 'weekshift -1))
+((eq key 'lastmonth) (setq key 'month   shift -1))
+((eq key 'lastyear)  (setq key 'yearshift -1))
+((eq key 'lastq) (setq key 'quarter 

Re: [Orgmode] [PATCH] Quarters added to clocktables

2010-11-26 Thread Carsten Dominik

Hi Erwin,

this patch looks good.  However, it does not apply cleanly to the  
current head, and I need to ask you to sign the FSF papers for it.   
Are you willing to do this?


Thanks

- Carsten

On Nov 19, 2010, at 2:00 PM, Erwin Vrolijk wrote:


Hi,

I'm proud to present my first patch to orgmode.
With this patch quarters are added to clocktables. It is now  
possible to show data for a quarter via the following syntax:


:block thisq[-n] or
:block lastq
:block 2010-Q2

Other places where quarters might be handy (for instance repeating  
events quarterly) are still todo.


I've patched two files, the main file lisp/org-clock.el and the  
documentation in doc/org.texti


Regards,
Erwin Vrolijk
http://snow.nl

diff --git a/doc/org.texi b/doc/org.texi
index 06583d7..5f07dbd 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -5820,6 +5820,7 @@ be selected:
2007-12-31@r{New year eve 2007}
2007-12   @r{December 2007}
2007-W50  @r{ISO-week 50 in 2007}
+ 2007-Q2   @r{2nd quarter in 2007}
2007  @r{the year 2007}
today, yesterday, tod...@var{n}  @r{a relative  
day}
thisweek, lastweek, thiswe...@var{n} @r{a relative  
week}



diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3146926..1301fb8 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1653,6 +1653,64 @@ buffer and update it.
 (re-search-forward ^[ \t]+#\\+END:.* nil t)
 (= (match-end 0) pos)
 start
+(defun org-day-of-week (day month year)
+  Returns the day of the week as an integer.
+  (nth 6
+   (decode-time
+   (date-to-time
+(format %d-%02d-%02dT00:00:00 year month day)
+
+(defun org-quarter-to-date (quarter year)
+  Get the date (week day year) of the first day of a given quarter.
+  (cond
+   ((= quarter 1)
+(setq startday (org-day-of-week 1 1 year))
+(cond
+ ((= startday 0)
+  (list 52 7 (- year 1)))
+ ((= startday 6)
+  (list 52 6 (- year 1)))
+ ((= startday 4)
+  (list 1 startday year))
+ (( startday 4)
+  (list 53 startday (- year 1)))
+ )
+)
+   ((= quarter 2)
+(setq startday (org-day-of-week 1 4 year))
+(cond
+ ((= startday 0)
+  (list 13 startday year))
+ (( startday 4)
+  (list 14 startday year))
+ ((= startday 4)
+  (list 13 startday year))
+ )
+)
+   ((= quarter 3)
+(setq startday (org-day-of-week 1 7 year))
+(cond
+ ((= startday 0)
+  (list 26 startday year))
+ (( startday 4)
+  (list 27 startday year))
+ ((= startday 4)
+  (list 26 startday year))
+ )
+)
+   ((= quarter 4)
+(setq startday (org-day-of-week 1 10 year))
+(cond
+ ((= startday 0)
+  (list 39 startday year))
+ ((= startday 4)
+  (list 40 startday year))
+ (( startday 4)
+  (list 39 startday year))
+ )
+)
+   )
+  )
(defun org-clock-special-range (key optional time as-strings)
 Return two times bordering a special time range.
@@ -1670,6 +1728,10 @@ the returned times will be formatted strings.
   (dow (nth 6 tm))
   (skey (symbol-name key))
   (shift 0)
+(q (cond ((= (nth 4 tm) 10) 4)
+ ((= (nth 4 tm) 7) 3)
+ ((= (nth 4 tm) 4) 2)
+ ((= (nth 4 tm) 1) 1)))
   s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
   (cond
((string-match ^[0-9]+$ skey)
@@ -1687,19 +1749,35 @@ the returned times will be formatted strings.
 (setq d (nth 1 date) month (car date) y (nth 2 date)
  dow 1
  key 'week))
+ ((string-match ^\\([0-9]+\\)-[qQ]\\([1-4]\\)$ skey)
+  (require 'cal-iso)
+  (setq y (string-to-number (match-string 1 skey)))
+  (setq q (string-to-number (match-string 2 skey)))
+  (setq date (calendar-gregorian-from-absolute
+  (calendar-absolute-from-iso (org-quarter-to-date  
q y

+  (setq d (nth 1 date) month (car date) y (nth 2 date)
+   dow 1
+   key 'quarter))
((string-match ^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\ 
\{1,2\\}\\)$ skey)

 (setq y (string-to-number (match-string 1 skey))
  month (string-to-number (match-string 2 skey))
  d (string-to-number (match-string 3 skey))
  key 'day))
+ ; looking forward with quarters is not implemented yet.
+; ((string-match \\(\\(?:[-]\\|\\(?:!q\\)[+]\\)[0-9]+\\)$ skey)
((string-match \\([-+][0-9]+\\)$ skey)
 (setq shift (string-to-number (match-string 1 skey))
-   key (intern (substring skey 0 (match-beginning 1))
+   key (intern (substring skey 0 (match-beginning 1
+  (if(and (memq key '(quarter thisq)) ( shift 0))
+(error Looking forward with quarters isn't implemented.)
+   (
+
   (when (= shift 0)
-  (cond ((eq key 'yesterday) (setq key 'today shift -1))
-   ((eq key 'lastweek)  (setq key 'week  shift -1))
-   ((eq key 

[Orgmode] [PATCH] Quarters added to clocktables

2010-11-19 Thread Erwin Vrolijk

Hi,

I'm proud to present my first patch to orgmode.
With this patch quarters are added to clocktables. It is now possible to 
show data for a quarter via the following syntax:


:block thisq[-n] or
:block lastq
:block 2010-Q2

Other places where quarters might be handy (for instance repeating 
events quarterly) are still todo.


I've patched two files, the main file lisp/org-clock.el and the 
documentation in doc/org.texti


Regards,
Erwin Vrolijk
http://snow.nl

diff --git a/doc/org.texi b/doc/org.texi
index 06583d7..5f07dbd 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -5820,6 +5820,7 @@ be selected:
 2007-12-31@r{New year eve 2007}
 2007-12   @r{December 2007}
 2007-W50  @r{ISO-week 50 in 2007}
+ 2007-Q2   @r{2nd quarter in 2007}
 2007  @r{the year 2007}
 today, yesterday, tod...@var{n}  @r{a relative day}
 thisweek, lastweek, thiswe...@var{n} @r{a relative week}


diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3146926..1301fb8 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1653,6 +1653,64 @@ buffer and update it.
  (re-search-forward ^[ \t]+#\\+END:.* nil t)
  (= (match-end 0) pos)
  start
+(defun org-day-of-week (day month year)
+  Returns the day of the week as an integer.
+  (nth 6
+   (decode-time
+   (date-to-time
+(format %d-%02d-%02dT00:00:00 year month day)
+
+(defun org-quarter-to-date (quarter year)
+  Get the date (week day year) of the first day of a given quarter.
+  (cond
+   ((= quarter 1)
+(setq startday (org-day-of-week 1 1 year))
+(cond
+ ((= startday 0)
+  (list 52 7 (- year 1)))
+ ((= startday 6)
+  (list 52 6 (- year 1)))
+ ((= startday 4)
+  (list 1 startday year))
+ (( startday 4)
+  (list 53 startday (- year 1)))
+ )
+)
+   ((= quarter 2)
+(setq startday (org-day-of-week 1 4 year))
+(cond
+ ((= startday 0)
+  (list 13 startday year))
+ (( startday 4)
+  (list 14 startday year))
+ ((= startday 4)
+  (list 13 startday year))
+ )
+)
+   ((= quarter 3)
+(setq startday (org-day-of-week 1 7 year))
+(cond
+ ((= startday 0)
+  (list 26 startday year))
+ (( startday 4)
+  (list 27 startday year))
+ ((= startday 4)
+  (list 26 startday year))
+ )
+)
+   ((= quarter 4)
+(setq startday (org-day-of-week 1 10 year))
+(cond
+ ((= startday 0)
+  (list 39 startday year))
+ ((= startday 4)
+  (list 40 startday year))
+ (( startday 4)
+  (list 39 startday year))
+ )
+)
+   )
+  )

(defun org-clock-special-range (key optional time as-strings)
  Return two times bordering a special time range.
@@ -1670,6 +1728,10 @@ the returned times will be formatted strings.
(dow (nth 6 tm))
(skey (symbol-name key))
(shift 0)
+(q (cond ((= (nth 4 tm) 10) 4)
+ ((= (nth 4 tm) 7) 3)
+ ((= (nth 4 tm) 4) 2)
+ ((= (nth 4 tm) 1) 1)))
s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
(cond
 ((string-match ^[0-9]+$ skey)
@@ -1687,19 +1749,35 @@ the returned times will be formatted strings.
  (setq d (nth 1 date) month (car date) y (nth 2 date)
   dow 1
   key 'week))
+ ((string-match ^\\([0-9]+\\)-[qQ]\\([1-4]\\)$ skey)
+  (require 'cal-iso)
+  (setq y (string-to-number (match-string 1 skey)))
+  (setq q (string-to-number (match-string 2 skey)))
+  (setq date (calendar-gregorian-from-absolute
+  (calendar-absolute-from-iso (org-quarter-to-date q y
+  (setq d (nth 1 date) month (car date) y (nth 2 date)
+   dow 1
+   key 'quarter))
 ((string-match 
^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$ skey)

  (setq y (string-to-number (match-string 1 skey))
   month (string-to-number (match-string 2 skey))
   d (string-to-number (match-string 3 skey))
   key 'day))
+ ; looking forward with quarters is not implemented yet.
+; ((string-match \\(\\(?:[-]\\|\\(?:!q\\)[+]\\)[0-9]+\\)$ skey)
 ((string-match \\([-+][0-9]+\\)$ skey)
  (setq shift (string-to-number (match-string 1 skey))
-   key (intern (substring skey 0 (match-beginning 1))
+   key (intern (substring skey 0 (match-beginning 1
+  (if(and (memq key '(quarter thisq)) ( shift 0))
+(error Looking forward with quarters isn't implemented.)
+   (
+
(when (= shift 0)
-  (cond ((eq key 'yesterday) (setq key 'today shift -1))
-   ((eq key 'lastweek)  (setq key 'week  shift -1))
-   ((eq key 'lastmonth) (setq key 'month shift -1))
-   ((eq key 'lastyear)  (setq key 'year  shift -1
+  (cond ((eq key 'yesterday) (setq key 'today   shift -1))
+   ((eq key 'lastweek)  (setq key 'weekshift -1))
+