Mercurial > emacs
annotate lisp/calendar/cal-iso.el @ 20892:18f3cb26243f before-miles-orphaned-changes gcc-2_8_1-980401 gcc-2_8_1-980407 gcc-2_8_1-980412 gcc-2_8_1-980413 gcc-2_8_1-RELEASE gcc_2_8_1-980315 libc-980214 libc-980215 libc-980216 libc-980217 libc-980218 libc-980219 libc-980220 libc-980221 libc-980222 libc-980223 libc-980224 libc-980225 libc-980226 libc-980227 libc-980228 libc-980301 libc-980302 libc-980303 libc-980304 libc-980306 libc-980307 libc-980308 libc-980309 libc-980310 libc-980311 libc-980312 libc-980313 libc-980314 libc-980315 libc-980316 libc-980317 libc-980318 libc-980319 libc-980320 libc-980321 libc-980322 libc-980323 libc-980324 libc-980325 libc-980326 libc-980327 libc-980328 libc-980329 libc-980330 libc-980331 libc-980401 libc-980402 libc-980403 libc-980404 libc-980405 libc-980406 libc-980407 libc-980408 libc-980409 libc-980410 libc-980411 libc-980412 libc-980413 libc-980414 libc-980428 libc-980429 libc-980430 libc-980501 libc-980502 libc-980503 libc-980504 libc-980505 libc-980506 libc-980507 libc-980508 libc-980509 libc-980510 libc-980512 libc-980513 libc-980514 libc-980515 libc-980516 libc-980517 libc-980518 libc-980519 libc-980520 libc-980521 libc-980522 libc-980523 libc-980524 libc-980525 libc-980526 libc-980527 libc-980528 libc-980529 libc-980530 libc-980531 libc-980601 libc-980602 libc-980603 libc-980604 libc-980605 libc-980606 libc-980607 libc-980608 libc-980609 libc-980610 libc-980611 libc-980612 libc-980613
Add PentiumII (i786). Add '7' to all i[3456] entries.
Add AMD and Cyrix names for P5 and P6.
author | Richard Kenner <kenner@gnu.org> |
---|---|
date | Fri, 13 Feb 1998 12:16:46 +0000 |
parents | d179de7ad92e |
children | 7a94f1c588c4 |
rev | line source |
---|---|
13053 | 1 ;;; cal-iso.el --- calendar functions for the ISO calendar. |
2 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
3 ;; Copyright (C) 1995, 1997 Free Software Foundation, Inc. |
13053 | 4 |
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
6 ;; Keywords: calendar | |
7 ;; Human-Keywords: ISO calendar, calendar, diary | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
13053 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This collection of functions implements the features of calendar.el and | |
29 ;; diary.el that deal with the ISO calendar. | |
30 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
31 ;; Technical details of all the calendrical calculations can be found in |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
32 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold, |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
33 ;; Cambridge University Press (1997). |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
14169
diff
changeset
|
34 |
13053 | 35 ;; Comments, corrections, and improvements should be sent to |
36 ;; Edward M. Reingold Department of Computer Science | |
37 ;; (217) 333-6733 University of Illinois at Urbana-Champaign | |
38 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue | |
39 ;; Urbana, Illinois 61801 | |
40 | |
41 ;;; Code: | |
42 | |
43 (require 'calendar) | |
44 | |
45 (defun calendar-absolute-from-iso (date) | |
46 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE. | |
47 The `ISO year' corresponds approximately to the Gregorian year, but | |
48 weeks start on Monday and end on Sunday. The first week of the ISO year is | |
49 the first such week in which at least 4 days are in a year. The ISO | |
50 commercial DATE has the form (week day year) in which week is in the range | |
51 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = | |
52 Sunday). The Gregorian date Sunday, December 31, 1 BC is imaginary." | |
53 (let* ((week (extract-calendar-month date)) | |
54 (day (extract-calendar-day date)) | |
55 (year (extract-calendar-year date))) | |
56 (+ (calendar-dayname-on-or-before | |
57 1 (+ 3 (calendar-absolute-from-gregorian (list 1 1 year)))) | |
58 (* 7 (1- week)) | |
59 (if (= day 0) 6 (1- day))))) | |
60 | |
61 (defun calendar-iso-from-absolute (date) | |
62 "Compute the `ISO commercial date' corresponding to the absolute DATE. | |
63 The ISO year corresponds approximately to the Gregorian year, but weeks | |
64 start on Monday and end on Sunday. The first week of the ISO year is the | |
65 first such week in which at least 4 days are in a year. The ISO commercial | |
66 date has the form (week day year) in which week is in the range 1..52 and | |
67 day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The | |
68 absolute date is the number of days elapsed since the (imaginary) Gregorian | |
69 date Sunday, December 31, 1 BC." | |
70 (let* ((approx (extract-calendar-year | |
71 (calendar-gregorian-from-absolute (- date 3)))) | |
72 (year (+ approx | |
73 (calendar-sum y approx | |
74 (>= date (calendar-absolute-from-iso (list 1 1 (1+ y)))) | |
75 1)))) | |
76 (list | |
77 (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7)) | |
78 (% date 7) | |
79 year))) | |
80 | |
81 (defun calendar-iso-date-string (&optional date) | |
82 "String of ISO date of Gregorian DATE. | |
83 Defaults to today's date if DATE is not given." | |
84 (let* ((d (calendar-absolute-from-gregorian | |
85 (or date (calendar-current-date)))) | |
86 (day (% d 7)) | |
87 (iso-date (calendar-iso-from-absolute d))) | |
88 (format "Day %s of week %d of %d" | |
89 (if (zerop day) 7 day) | |
90 (extract-calendar-month iso-date) | |
91 (extract-calendar-year iso-date)))) | |
92 | |
93 (defun calendar-print-iso-date () | |
94 "Show equivalent ISO date for the date under the cursor." | |
95 (interactive) | |
96 (message "ISO date: %s" | |
97 (calendar-iso-date-string (calendar-cursor-to-date t)))) | |
98 | |
99 (defun calendar-goto-iso-date (date &optional noecho) | |
100 "Move cursor to ISO DATE; echo ISO date unless NOECHO is t." | |
101 (interactive | |
102 (let* ((today (calendar-current-date)) | |
103 (year (calendar-read | |
104 "ISO calendar year (>0): " | |
105 '(lambda (x) (> x 0)) | |
106 (int-to-string (extract-calendar-year today)))) | |
107 (no-weeks (extract-calendar-month | |
108 (calendar-iso-from-absolute | |
109 (1- | |
110 (calendar-dayname-on-or-before | |
111 1 (calendar-absolute-from-gregorian | |
112 (list 1 4 (1+ year)))))))) | |
113 (week (calendar-read | |
114 (format "ISO calendar week (1-%d): " no-weeks) | |
115 '(lambda (x) (and (> x 0) (<= x no-weeks))))) | |
116 (day (calendar-read | |
117 "ISO day (1-7): " | |
118 '(lambda (x) (and (<= 1 x) (<= x 7)))))) | |
119 (list (list week day year)))) | |
120 (calendar-goto-date (calendar-gregorian-from-absolute | |
121 (calendar-absolute-from-iso date))) | |
122 (or noecho (calendar-print-iso-date))) | |
123 | |
124 (defun diary-iso-date () | |
125 "ISO calendar equivalent of date diary entry." | |
126 (format "ISO date: %s" (calendar-iso-date-string date))) | |
127 | |
128 (provide 'cal-iso) | |
129 | |
130 ;;; cal-iso.el ends here |