aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorRichard M. Stallman1996-07-23 14:00:08 +0000
committerRichard M. Stallman1996-07-23 14:00:08 +0000
commit236ebf3525b654326eb6afd21363fa8e3263b06e (patch)
tree4e454ce1222666e688d776556424eb888fb2acc0 /src/editfns.c
parent0f93e41fda9e3d3eda2206af352c8aef23d2d90e (diff)
downloademacs-236ebf3525b654326eb6afd21363fa8e3263b06e.tar.gz
emacs-236ebf3525b654326eb6afd21363fa8e3263b06e.zip
(Fdecode_time, difftm): Work even if tm_year represents
negative years; this is possible with 64-bit time_t values.
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/editfns.c b/src/editfns.c
index c33a6acae8b..164ee9c6e80 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -693,7 +693,7 @@ ZONE is an integer indicating the number of seconds east of Greenwich.\n\
693 XSETFASTINT (list_args[2], decoded_time->tm_hour); 693 XSETFASTINT (list_args[2], decoded_time->tm_hour);
694 XSETFASTINT (list_args[3], decoded_time->tm_mday); 694 XSETFASTINT (list_args[3], decoded_time->tm_mday);
695 XSETFASTINT (list_args[4], decoded_time->tm_mon + 1); 695 XSETFASTINT (list_args[4], decoded_time->tm_mon + 1);
696 XSETFASTINT (list_args[5], decoded_time->tm_year + 1900); 696 XSETINT (list_args[5], decoded_time->tm_year + 1900);
697 XSETFASTINT (list_args[6], decoded_time->tm_wday); 697 XSETFASTINT (list_args[6], decoded_time->tm_wday);
698 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil; 698 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil;
699 699
@@ -828,14 +828,17 @@ difftm (a, b)
828{ 828{
829 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); 829 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
830 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); 830 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
831 /* Divide years by 100, rounding towards minus infinity. */
832 int ac = ay / 100 - (ay % 100 < 0);
833 int bc = by / 100 - (by % 100 < 0);
831 /* Some compilers can't handle this as a single return statement. */ 834 /* Some compilers can't handle this as a single return statement. */
832 long days = ( 835 long days = (
833 /* difference in day of year */ 836 /* difference in day of year */
834 a->tm_yday - b->tm_yday 837 a->tm_yday - b->tm_yday
835 /* + intervening leap days */ 838 /* + intervening leap days */
836 + ((ay >> 2) - (by >> 2)) 839 + ((ay >> 2) - (by >> 2))
837 - (ay/100 - by/100) 840 - (ac - bc)
838 + ((ay/100 >> 2) - (by/100 >> 2)) 841 + ((ac >> 2) - (bc >> 2))
839 /* + difference in years * 365 */ 842 /* + difference in years * 365 */
840 + (long)(ay-by) * 365 843 + (long)(ay-by) * 365
841 ); 844 );