all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: The Emacs Calculator and calendar
Date: Sun, 07 Oct 2012 23:30:52 -0700	[thread overview]
Message-ID: <5072731C.8000408@cs.ucla.edu> (raw)
In-Reply-To: <jwvlifh24gq.fsf-monnier+emacs@gnu.org>

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  <eggert@cs.ucla.edu>
+
+	Calc now uses the Gregorian calendar for all dates.
+	* calc.texi (Date Forms): Use the Gregorian calendar uniformly.
+
 2012-10-06  Glenn Morris  <rgm@gnu.org>
 
 	* 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.
-
-@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{<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
-@samp{<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  <eggert@cs.ucla.edu>
+
+	Calc now uses the Gregorian calendar for all dates.
+	* NEWS (Calc): Document this.
+
 2012-10-07  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* 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  <eggert@cs.ucla.edu>
+
+	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  <fgallina@cuca>
 
 	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	other threads:[~2012-10-08  6:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05 19:13 The Emacs Calculator and calendar Jay Belanger
2012-10-05 19:24 ` Paul Eggert
2012-10-05 20:51 ` Edward Reingold
2012-10-05 21:14   ` Pascal J. Bourguignon
2012-10-06 15:41   ` Richard Stallman
2012-10-06 22:07     ` Paul Eggert
2012-10-07  3:49       ` Richard Stallman
2012-10-07  6:22         ` Paul Eggert
2012-10-07 17:30           ` Richard Stallman
2012-10-07 18:23             ` Paul Eggert
2012-10-10  3:37               ` Richard Stallman
2012-10-07  6:36       ` Eli Zaretskii
2012-10-07  7:50         ` Paul Eggert
2012-10-07  8:45           ` Eli Zaretskii
2012-10-07 13:01             ` Juanma Barranquero
2012-10-07 14:08               ` Eli Zaretskii
2012-10-07 17:30           ` Richard Stallman
2012-10-07 17:57             ` Juanma Barranquero
2012-10-07 21:55         ` Sam Steingold
2012-10-08 13:39           ` Richard Stallman
2012-10-07  8:17       ` Stephen J. Turnbull
2012-10-07  7:56     ` Achim Gratz
2012-10-07  8:44       ` Eli Zaretskii
2012-10-07 13:57         ` Stefan Monnier
2012-10-07 20:32           ` Paul Eggert
2012-10-07 21:34             ` Tim Cross
2012-10-08  0:32             ` Stefan Monnier
2012-10-08  6:30               ` Paul Eggert [this message]
2012-10-08  7:28                 ` Ulrich Mueller
2012-10-08 13:56                   ` Stefan Monnier
2012-10-08 14:49                     ` Jay Belanger
2012-10-08  8:21                 ` James Cloos
2012-10-08 14:59                 ` Jay Belanger
2012-10-13  6:02                   ` Paul Eggert
2012-10-13 14:05                     ` Jay Belanger
2012-10-08 13:39             ` Richard Stallman
2012-10-08 19:34               ` Paul Eggert
2012-10-08 22:39                 ` Richard Stallman
2012-10-09  6:28                   ` Paul Eggert
2012-10-09 15:47                     ` Richard Stallman
2012-10-09 23:10                       ` Paul Eggert
2012-10-10  2:22                         ` Jay Belanger
2012-10-11 12:09                           ` Jason Rumney
2012-10-12  1:52                             ` Richard Stallman
2012-10-10  3:37                         ` Richard Stallman
2012-10-10 21:42                   ` Christoph Herzog
2012-10-05 21:17 ` Edward Reingold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5072731C.8000408@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.