Mercurial > emacs
comparison src/editfns.c @ 5882:319a7fcb7609
(difftm): Simplify expression.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 10 Feb 1994 20:27:34 +0000 |
parents | a70b89d2d6bb |
children | d02095ea13a5 |
comparison
equal
deleted
inserted
replaced
5881:678a8470e4d1 | 5882:319a7fcb7609 |
---|---|
609 | 609 |
610 #define TM_YEAR_ORIGIN 1900 | 610 #define TM_YEAR_ORIGIN 1900 |
611 | 611 |
612 /* Yield A - B, measured in seconds. */ | 612 /* Yield A - B, measured in seconds. */ |
613 static long | 613 static long |
614 difftm(a, b) | 614 difftm (a, b) |
615 struct tm *a, *b; | 615 struct tm *a, *b; |
616 { | 616 { |
617 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); | 617 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
618 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); | 618 int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
619 return | 619 /* Some compilers can't handle this as a single return statement. */ |
620 ( | 620 int days = ( |
621 ( | 621 /* difference in day of year */ |
622 ( | 622 a->tm_yday - b->tm_yday |
623 /* difference in day of year */ | 623 /* + intervening leap days */ |
624 a->tm_yday - b->tm_yday | 624 + ((ay >> 2) - (by >> 2)) |
625 /* + intervening leap days */ | 625 - (ay/100 - by/100) |
626 + ((ay >> 2) - (by >> 2)) | 626 + ((ay/100 >> 2) - (by/100 >> 2)) |
627 - (ay/100 - by/100) | 627 /* + difference in years * 365 */ |
628 + ((ay/100 >> 2) - (by/100 >> 2)) | 628 + (long)(ay-by) * 365 |
629 /* + difference in years * 365 */ | 629 ); |
630 + (long)(ay-by) * 365 | 630 return (60*(60*(24*days + (a->tm_hour - b->tm_hour)) |
631 )*24 + (a->tm_hour - b->tm_hour) | 631 + (a->tm_min - b->tm_min)) |
632 )*60 + (a->tm_min - b->tm_min) | 632 + (a->tm_sec - b->tm_sec)); |
633 )*60 + (a->tm_sec - b->tm_sec); | |
634 } | 633 } |
635 | 634 |
636 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0, | 635 DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0, |
637 "Return the offset and name for the local time zone.\n\ | 636 "Return the offset and name for the local time zone.\n\ |
638 This returns a list of the form (OFFSET NAME).\n\ | 637 This returns a list of the form (OFFSET NAME).\n\ |