emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The Emacs Calculator and calendar


From: Paul Eggert
Subject: Re: The Emacs Calculator and calendar
Date: Sun, 07 Oct 2012 23:30:52 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1

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?

=== 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  <address@hidden>
+
+       Calc now uses the Gregorian calendar for all dates.
+       * calc.texi (Date Forms): Use the Gregorian calendar uniformly.
+
 2012-10-06  Glenn Morris  <address@hidden>
 
        * erc.texi: Include emacsver.texi, and use EMACSVER rather than

=== 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}.
 
 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.
-
address@hidden Julian calendar
address@hidden 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
address@hidden<Mon Jan 1, +1>} is @samp{<Sun Dec 31, -1>}.  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.
 
 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>}.)
 
-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
address@hidden<Sat Jan 1, +1>} is @samp{<Fri Dec 31, -1>}.  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

=== 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  <address@hidden>
+
+       Calc now uses the Gregorian calendar for all dates.
+       * NEWS (Calc): Document this.
+
 2012-10-07  Jan Djärv  <address@hidden>
 
        * NEWS (NextStep/OSX port changes): OSX 10.4 or newer is required.

=== 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.
 
+** 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
 
 *** You can customize the header text that appears above each calendar month.

=== 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  <address@hidden>
+
+       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
+       <http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00298.html>.
+       * 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án Ezequiel Gallina  <address@hidden>
 
        Enhancements on forward-sexp movement.

=== 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 @@
 
 ;;; 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 Gregorian
-;;; calendar is used; the first day after 9/2/1752 is 9/14/1752.
+;;; The Gregorian calendar is used even for older dates.
 
 ;;; 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), corresponding
 ;;; 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) (>= 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)))
 
 (defun math-leap-year-p (year)
-  (if (Math-lessp year 1752)
       (if (math-negp year)
-         (= (math-imod (math-neg year) 4) 1)
-       (= (math-imod year 4) 0))
+      (setq year (math-add 1 year)))
     (setq year (math-imod year 400))
     (or (and (= (% year 4) 0) (/= (% year 100) 0))
-       (= year 0))))
+      (= year 0)))
 
 (defun math-days-in-month (year month)
   (if (and (= 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 (= month 9) (>= day 14)))
-        (setq day-of-year (- day-of-year 11)))
     day-of-year))
 
 (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) (<= month 9)))
-                 1
                (let ((correction (math-mul (math-quotient yearm1 100) 3)))
                  (let ((res (math-idivmod correction 4)))
                    (math-add (if (= (cdr res) 0)
                                  -1
                                0)
-                             (car res))))))))
+                           (car res)))))))
 
 
 ;;; It is safe to redefine these in your init file to use a different
@@ -550,11 +538,11 @@
 
 (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).")
 
 (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 1AD.")
+as measured in the integer number of days before December 30, 1 BC 
(Gregorian).")
 
 (defun math-format-date-part (x)
   (cond ((stringp x)
@@ -1437,8 +1425,6 @@
   (let ((dt (math-date-to-dt date)))
     (if (or (= 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) (= (nth 1 dt) 9)
-        (if (>= day 14) (setq day (- day 11))))
     (list 'date (math-add (math-dt-to-date (list (car dt) (nth 1 dt) 1))
                          (1- day)))))
 
@@ -1448,8 +1434,7 @@
   (or (integerp day) (math-reject-arg day 'fixnump))
   (let ((dt (math-date-to-dt date)))
     (if (and (>= day 0) (<= 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 (= 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))
 
-;;; Compute the number of business days since Jan 1, 1 AD.
+;;; Compute the number of business days since December 30, 1 BC (Gregorian).
 
 (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)))
 
 
-;;; 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.
 
 (defun math-from-business-day (num)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]