Mercurial > emacs
annotate lisp/calendar/cal-iso.el @ 92986:589bafdc6c3e
Craig Markwardt <Craig.Markwardt at nasa.gov>
(icalendar-recurring-start-year): New variable.
(icalendar--diarytime-to-isotime): Fix treatment of 12:00pm - 12:59pm.
(icalendar-export-region): Ignore hidden diary entries.
(icalendar--convert-ordinary-to-ical): Fix case where event
spans across midnight boundary.
(icalendar-first-weekday-of-year): New function.
(icalendar--convert-weekly-to-ical): Allow user-selectable start
year for recurring events (Mozilla calendars do not propagate
recurring events forever, so year 2000 start date was not working).
(icalendar--convert-yearly-to-ical): Remove extra spaces in
formatting of BYMONTH and BYMONTHDAY (not allowed by ical spec).
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 16 Mar 2008 01:21:25 +0000 |
parents | d77fc175bcfc |
children | 5a7437fafea3 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
20462
diff
changeset
|
1 ;;; cal-iso.el --- calendar functions for the ISO calendar |
13053 | 2 |
92609 | 3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4 ;; 2008 Free Software Foundation, Inc. | |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
65919
5c09efcfc1d9
Update maintainer email address.
Glenn Morris <rgm@gnu.org>
parents:
65145
diff
changeset
|
7 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
13053 | 8 ;; Keywords: calendar |
9 ;; Human-Keywords: ISO calendar, calendar, diary | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78216
93e11478c954
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
13053 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
13053 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This collection of functions implements the features of calendar.el and | |
31 ;; diary.el that deal with the ISO calendar. | |
32 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
33 ;; Technical details of all the calendrical calculations can be found in |
61148
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
57324
diff
changeset
|
34 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold |
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
57324
diff
changeset
|
35 ;; and Nachum Dershowitz, Cambridge University Press (2001). |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
36 |
13053 | 37 ;;; Code: |
38 | |
39 (require 'calendar) | |
40 | |
41 (defun calendar-absolute-from-iso (date) | |
42 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. | |
43 The `ISO year' corresponds approximately to the Gregorian year, but | |
44 weeks start on Monday and end on Sunday. The first week of the ISO year is | |
45 the first such week in which at least 4 days are in a year. The ISO | |
46 commercial DATE has the form (week day year) in which week is in the range | |
47 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = | |
48 Sunday). The Gregorian date Sunday, December 31, 1 BC is imaginary." | |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
49 (let ((day (extract-calendar-day date))) |
13053 | 50 (+ (calendar-dayname-on-or-before |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
51 1 (+ 3 (calendar-absolute-from-gregorian |
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
52 (list 1 1 (extract-calendar-year date))))) |
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
53 ;; ISO date is (week day year); normally (month day year). |
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
54 (* 7 (1- (extract-calendar-month date))) |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
55 (if (zerop day) 6 (1- day))))) |
13053 | 56 |
57 (defun calendar-iso-from-absolute (date) | |
58 "Compute the `ISO commercial date' corresponding to the absolute DATE. | |
59 The ISO year corresponds approximately to the Gregorian year, but weeks | |
60 start on Monday and end on Sunday. The first week of the ISO year is the | |
61 first such week in which at least 4 days are in a year. The ISO commercial | |
62 date has the form (week day year) in which week is in the range 1..52 and | |
63 day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The | |
64 absolute date is the number of days elapsed since the (imaginary) Gregorian | |
65 date Sunday, December 31, 1 BC." | |
66 (let* ((approx (extract-calendar-year | |
67 (calendar-gregorian-from-absolute (- date 3)))) | |
68 (year (+ approx | |
69 (calendar-sum y approx | |
92902 | 70 (>= date (calendar-absolute-from-iso |
71 (list 1 1 (1+ y)))) | |
72 1)))) | |
13053 | 73 (list |
74 (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7)) | |
75 (% date 7) | |
76 year))) | |
77 | |
92833
272f566348a7
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92818
diff
changeset
|
78 ;;;###cal-autoload |
13053 | 79 (defun calendar-iso-date-string (&optional date) |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
80 "String of ISO date of Gregorian DATE, default today." |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38422
diff
changeset
|
81 (let* ((d (calendar-absolute-from-gregorian |
13053 | 82 (or date (calendar-current-date)))) |
83 (day (% d 7)) | |
84 (iso-date (calendar-iso-from-absolute d))) | |
85 (format "Day %s of week %d of %d" | |
86 (if (zerop day) 7 day) | |
87 (extract-calendar-month iso-date) | |
88 (extract-calendar-year iso-date)))) | |
89 | |
92833
272f566348a7
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92818
diff
changeset
|
90 ;;;###cal-autoload |
13053 | 91 (defun calendar-print-iso-date () |
92 "Show equivalent ISO date for the date under the cursor." | |
93 (interactive) | |
94 (message "ISO date: %s" | |
95 (calendar-iso-date-string (calendar-cursor-to-date t)))) | |
96 | |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
97 (defun calendar-iso-read-args (&optional dayflag) |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
98 "Interactively read the arguments for an ISO date command. |
92625
e26350e23411
(calendar-iso-read-args): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
92609
diff
changeset
|
99 Reads a year and week, and if DAYFLAG is non-nil a day (otherwise |
e26350e23411
(calendar-iso-read-args): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
92609
diff
changeset
|
100 taken to be 1)." |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
101 (let* ((year (calendar-read |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
102 "ISO calendar year (>0): " |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
103 (lambda (x) (> x 0)) |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
104 (int-to-string (extract-calendar-year |
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
105 (calendar-current-date))))) |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
106 (no-weeks (extract-calendar-month |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
107 (calendar-iso-from-absolute |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
108 (1- |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
109 (calendar-dayname-on-or-before |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
110 1 (calendar-absolute-from-gregorian |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
111 (list 1 4 (1+ year)))))))) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
112 (week (calendar-read |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
113 (format "ISO calendar week (1-%d): " no-weeks) |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
114 (lambda (x) (and (> x 0) (<= x no-weeks))))) |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
115 (day (if dayflag (calendar-read |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
116 "ISO day (1-7): " |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
117 (lambda (x) (and (<= 1 x) (<= x 7)))) |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
118 1))) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
119 (list (list week day year)))) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
120 |
92833
272f566348a7
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92818
diff
changeset
|
121 ;;;###cal-autoload |
13053 | 122 (defun calendar-goto-iso-date (date &optional noecho) |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
123 "Move cursor to ISO DATE; echo ISO date unless NOECHO is non-nil." |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
124 (interactive (calendar-iso-read-args t)) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
125 (calendar-goto-date (calendar-gregorian-from-absolute |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
126 (calendar-absolute-from-iso date))) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
127 (or noecho (calendar-print-iso-date))) |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
128 |
92833
272f566348a7
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92818
diff
changeset
|
129 ;;;###cal-autoload |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
130 (defun calendar-goto-iso-week (date &optional noecho) |
92818
3ed51c637a80
(calendar-absolute-from-iso, calendar-iso-read-args): Simplify.
Glenn Morris <rgm@gnu.org>
parents:
92625
diff
changeset
|
131 "Move cursor to ISO DATE; echo ISO date unless NOECHO is non-nil. |
57324
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
132 Interactively, goes to the first day of the specified week." |
f51c087984a0
Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
133 (interactive (calendar-iso-read-args)) |
13053 | 134 (calendar-goto-date (calendar-gregorian-from-absolute |
135 (calendar-absolute-from-iso date))) | |
136 (or noecho (calendar-print-iso-date))) | |
137 | |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
138 (defvar date) |
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
139 |
92609 | 140 ;; To be called from list-sexp-diary-entries, where DATE is bound. |
92833
272f566348a7
(generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents:
92818
diff
changeset
|
141 ;;;###diary-autoload |
13053 | 142 (defun diary-iso-date () |
143 "ISO calendar equivalent of date diary entry." | |
144 (format "ISO date: %s" (calendar-iso-date-string date))) | |
145 | |
146 (provide 'cal-iso) | |
147 | |
92586
15aa69393e42
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
79703
diff
changeset
|
148 ;; arch-tag: 3c0154cc-d30f-4981-9f60-42bdf7a468f6 |
13053 | 149 ;;; cal-iso.el ends here |