From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: The Emacs Calculator and calendar Date: Sun, 07 Oct 2012 23:30:52 -0700 Organization: UCLA Computer Science Department Message-ID: <5072731C.8000408@cs.ucla.edu> References: <87y5jk3f7d.fsf@gmail.com> <87626md8aj.fsf@Rainer.invalid> <83vcem6592.fsf@gnu.org> <5071E6E7.7080906@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1349677873 30222 80.91.229.3 (8 Oct 2012 06:31:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Oct 2012 06:31:13 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 08 08:31:18 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TL6s1-0006Gr-Hm for ged-emacs-devel@m.gmane.org; Mon, 08 Oct 2012 08:31:17 +0200 Original-Received: from localhost ([::1]:55926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL6rv-0003bd-HB for ged-emacs-devel@m.gmane.org; Mon, 08 Oct 2012 02:31:11 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL6rt-0003bQ-39 for emacs-devel@gnu.org; Mon, 08 Oct 2012 02:31:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TL6rr-0004zM-0T for emacs-devel@gnu.org; Mon, 08 Oct 2012 02:31:09 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:53871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL6rq-0004yZ-LF for emacs-devel@gnu.org; Mon, 08 Oct 2012 02:31:06 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 89255A60001; Sun, 7 Oct 2012 23:30:58 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rJXDQAin0znr; Sun, 7 Oct 2012 23:30:56 -0700 (PDT) Original-Received: from [192.168.1.3] (pool-108-23-119-2.lsanca.fios.verizon.net [108.23.119.2]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id AFAE239E8100; Sun, 7 Oct 2012 23:30:56 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:154215 Archived-At: On 10/07/2012 05:32 PM, Stefan Monnier wrote: > So for now, Emacs should use the same default calendar for Calc, > Calendar, and whatever else uses dates; and it should be the Gregorian > calendar regardless of the requested date. OK, here's a proposed patch to do that. I used diff -b to generate this patch, to avoid spurious differences due to indentation changes, but the actual patch will indent properly. Is this OK for 24.3? =3D=3D=3D modified file 'doc/misc/ChangeLog' --- doc/misc/ChangeLog 2012-10-06 01:42:02 +0000 +++ doc/misc/ChangeLog 2012-10-08 05:54:07 +0000 @@ -1,3 +1,8 @@ +2012-10-08 Paul Eggert + + Calc now uses the Gregorian calendar for all dates. + * calc.texi (Date Forms): Use the Gregorian calendar uniformly. + 2012-10-06 Glenn Morris =20 * erc.texi: Include emacsver.texi, and use EMACSVER rather than =3D=3D=3D modified file 'doc/misc/calc.texi' --- doc/misc/calc.texi 2012-10-05 07:38:05 +0000 +++ doc/misc/calc.texi 2012-10-08 05:52:10 +0000 @@ -11010,35 +11010,15 @@ of a date form. @xref{Packing and Unpacking}. =20 Date forms can go arbitrarily far into the future or past. Negative -year numbers represent years BC. Calc uses a combination of the -Gregorian and Julian calendars, following the history of Great -Britain and the British colonies. This is the same calendar that -is used by the @code{cal} program in most Unix implementations. - -@cindex Julian calendar -@cindex Gregorian calendar -Some historical background: The Julian calendar was created by -Julius Caesar in the year 46 BC as an attempt to fix the gradual -drift caused by the lack of leap years in the calendar used -until that time. The Julian calendar introduced an extra day in -all years divisible by four. After some initial confusion, the -calendar was adopted around the year we call 8 AD. Some centuries -later it became apparent that the Julian year of 365.25 days was -itself not quite right. In 1582 Pope Gregory XIII introduced the -Gregorian calendar, which added the new rule that years divisible -by 100, but not by 400, were not to be considered leap years -despite being divisible by four. Many countries delayed adoption -of the Gregorian calendar because of religious differences; -in Britain it was put off until the year 1752, by which time -the Julian calendar had fallen eleven days behind the true -seasons. So the switch to the Gregorian calendar in early -September 1752 introduced a discontinuity: The day after -Sep 2, 1752 is Sep 14, 1752. Calc follows this convention. -To take another example, Russia waited until 1918 before -adopting the new calendar, and thus needed to remove thirteen -days (between Feb 1, 1918 and Feb 14, 1918). This means that -Calc's reckoning will be inconsistent with Russian history between -1752 and 1918, and similarly for various other countries. +year numbers represent years BC. +There is no ``year 0''; the day before +@samp{} is @samp{}. These are +days 2 and 1 respectively in Calc's internal numbering scheme. + +Calc uses the Gregorian calendar for all dates, including dates +before the actual use of the Gregorian calendar. +Thus Calc's use of the day number @mathit{-10000} to +represent August 14, 28 BC should be taken with a grain of salt. =20 Today's timekeepers introduce an occasional ``leap second'' as well, but Calc does not take these minor effects into account. @@ -11046,15 +11026,6 @@ between, say, @samp{<12:00am Mon Jan 1, 1900>} and @samp{<12:00am Sat Jan 1, 2000>}.) =20 -Calc uses the Julian calendar for all dates before the year 1752, -including dates BC when the Julian calendar technically had not -yet been invented. Thus the claim that day number @mathit{-10000} is -called ``August 16, 28 BC'' should be taken with a grain of salt. - -Please note that there is no ``year 0''; the day before -@samp{} is @samp{}. These are -days 0 and @mathit{-1} respectively in Calc's internal numbering scheme. - @cindex Julian day counting Another day counting system in common use is, confusingly, also called ``Julian.'' The Julian day number is the numbers of days since =3D=3D=3D modified file 'etc/ChangeLog' --- etc/ChangeLog 2012-10-07 10:07:23 +0000 +++ etc/ChangeLog 2012-10-08 05:54:42 +0000 @@ -1,3 +1,8 @@ +2012-10-08 Paul Eggert + + Calc now uses the Gregorian calendar for all dates. + * NEWS (Calc): Document this. + 2012-10-07 Jan Dj=C3=A4rv =20 * NEWS (NextStep/OSX port changes): OSX 10.4 or newer is required. =3D=3D=3D modified file 'etc/NEWS' --- etc/NEWS 2012-10-07 10:07:23 +0000 +++ etc/NEWS 2012-10-08 05:48:55 +0000 @@ -278,6 +278,15 @@ *** Option `Buffer-menu-buffer+size-width' is now obsolete. Use `Buffer-menu-name-width' and `Buffer-menu-size-width' instead. =20 +** Calc + +*** Calc now uses the Gregorian calendar for all dates. This is +consistent with how Calendar behaves. Previously Calc used the Julian +calendar for dates before September 14, 1752, under the theory that +this corresponded to the history of England and of British colonies, +but this theory is incorrect -- for example, the year 1751 was a short +year of 282 days in England. + ** Calendar =20 *** You can customize the header text that appears above each calendar m= onth. =3D=3D=3D modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-08 05:19:15 +0000 +++ lisp/ChangeLog 2012-10-08 06:02:16 +0000 @@ -1,3 +1,19 @@ +2012-10-08 Paul Eggert + + Calc now uses the Gregorian calendar for all dates. + This is more consistent with Calendar. Previously, Calc used the + Julian calendar for dates before September 14, 1752, under the + theory that this corresponded to the history of England and of + British colonies, but this theory is incorrect -- for example, the + year 1751 was a short year of 282 days in England. + Problem reported by Jay Belanger in + . + * calc/calc-forms.el (math-date-to-dt, math-leap-year-p) + (math-day-number, math-absolute-from-date) + (math-julian-date-beginning, math-julian-date-beginning-int) + (calcFunc-newmonth, calcFunc-newyear): + Implement this. + 2012-10-08 Fabi=C3=A1n Ezequiel Gallina =20 Enhancements on forward-sexp movement. =3D=3D=3D modified file 'lisp/calc/calc-forms.el' --- lisp/calc/calc-forms.el 2012-09-17 05:41:04 +0000 +++ lisp/calc/calc-forms.el 2012-10-08 05:55:23 +0000 @@ -369,12 +369,11 @@ =20 ;;; Some of these functions are adapted from Edward Reingold's "calendar= .el". ;;; These versions are rewritten to use arbitrary-size integers. -;;; The Julian calendar is used up to 9/2/1752, after which the Gregoria= n -;;; calendar is used; the first day after 9/2/1752 is 9/14/1752. +;;; The Gregorian calendar is used even for older dates. =20 ;;; A numerical date is the number of days since midnight on -;;; the morning of January 1, 1 A.D. If the date is a non-integer, -;;; it represents a specific date and time. +;;; the morning of December 30, 1 BC (Gregorian). +;;; If the date is a non-integer, it represents a specific date and time= . ;;; A "dt" is a list of the form, (year month day), corresponding to ;;; an integer code, or (year month day hour minute second), correspondi= ng ;;; to a non-integer code. @@ -390,8 +389,8 @@ (month 1) day (year (math-quotient (math-add date (if (Math-lessp date 711859) - 365 ; for speed, we take - -108)) ; >1950 as a special case + 367 ; for speed, we take + -106)) ; >1950 as a special case (if (math-negp value) 366 365))) ; this result may be an overestimate temp) @@ -399,8 +398,6 @@ (setq year (math-add year -1))) (if (eq year 0) (setq year -1)) (setq date (1+ (math-sub date temp))) - (and (eq year 1752) (>=3D date 247) - (setq date (+ date 11))) (setq temp (if (math-leap-year-p year) [1 32 61 92 122 153 183 214 245 275 306 336 999] [1 32 60 91 121 152 182 213 244 274 305 335 999])) @@ -447,13 +444,11 @@ (nth 5 (decode-time))) =20 (defun math-leap-year-p (year) - (if (Math-lessp year 1752) (if (math-negp year) - (=3D (math-imod (math-neg year) 4) 1) - (=3D (math-imod year 4) 0)) + (setq year (math-add 1 year))) (setq year (math-imod year 400)) (or (and (=3D (% year 4) 0) (/=3D (% year 100) 0)) - (=3D year 0)))) + (=3D year 0))) =20 (defun math-days-in-month (year month) (if (and (=3D month 2) (math-leap-year-p year)) @@ -467,10 +462,6 @@ (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10))) (if (math-leap-year-p year) (setq day-of-year (1+ day-of-year))))) - (and (eq year 1752) - (or (> month 9) - (and (=3D month 9) (>=3D day 14))) - (setq day-of-year (- day-of-year 11))) day-of-year)) =20 (defun math-absolute-from-date (year month day) @@ -483,15 +474,12 @@ (math-sub 365 (math-quotient (math-sub 3 year) 4))))) - (if (or (Math-lessp year 1753) - (and (eq year 1752) (<=3D month 9))) - 1 (let ((correction (math-mul (math-quotient yearm1 100) 3))) (let ((res (math-idivmod correction 4))) (math-add (if (=3D (cdr res) 0) -1 0) - (car res)))))))) + (car res))))))) =20 =20 ;;; It is safe to redefine these in your init file to use a different @@ -550,11 +538,11 @@ =20 (defconst math-julian-date-beginning '(float 17214235 -1) "The beginning of the Julian calendar, -as measured in the number of days before January 1 of the year 1AD.") +as measured in the number of days before December 30, 1 BC (Gregorian)."= ) =20 (defconst math-julian-date-beginning-int 1721424 "The beginning of the Julian calendar, -as measured in the integer number of days before January 1 of the year 1= AD.") +as measured in the integer number of days before December 30, 1 BC (Greg= orian).") =20 (defun math-format-date-part (x) (cond ((stringp x) @@ -1437,8 +1425,6 @@ (let ((dt (math-date-to-dt date))) (if (or (=3D day 0) (> day (math-days-in-month (car dt) (nth 1 dt)))= ) (setq day (math-days-in-month (car dt) (nth 1 dt)))) - (and (eq (car dt) 1752) (=3D (nth 1 dt) 9) - (if (>=3D day 14) (setq day (- day 11)))) (list 'date (math-add (math-dt-to-date (list (car dt) (nth 1 dt) 1)) (1- day))))) =20 @@ -1448,8 +1434,7 @@ (or (integerp day) (math-reject-arg day 'fixnump)) (let ((dt (math-date-to-dt date))) (if (and (>=3D day 0) (<=3D day 366)) - (let ((max (if (eq (car dt) 1752) 355 - (if (math-leap-year-p (car dt)) 366 365)))) + (let ((max (if (math-leap-year-p (car dt)) 366 365))) (if (or (=3D day 0) (> day max)) (setq day max)) (list 'date (math-add (math-dt-to-date (list (car dt) 1 1)) (1- day)))) @@ -1523,7 +1508,7 @@ (defun calcFunc-holiday (a) (if (cdr (math-to-business-day a)) 1 0)) =20 -;;; Compute the number of business days since Jan 1, 1 AD. +;;; Compute the number of business days since December 30, 1 BC (Gregori= an). =20 (defun math-to-business-day (date &optional need-year) (if (eq (car-safe date) 'date) @@ -1564,7 +1549,8 @@ (cons (math-add (math-sub day delta) time) holiday))) =20 =20 -;;; Compute the date a certain number of business days since Jan 1, 1 AD= . +;;; Compute the date from a certain number of business days since +;;; December 30, 1 BC (Gregorian). ;;; If this returns nil, holiday table was adjusted; redo calculation. =20 (defun math-from-business-day (num)