Mercurial > emacs
comparison src/editfns.c @ 11402:66d935214d8e
(Fencode_time): Use XINT to examine `zone'.
(Fencode_time): New function, to match `decode-time'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 12 Apr 1995 06:16:00 +0000 |
parents | 56feeecbb05a |
children | 6f7bdb6c3739 |
comparison
equal
deleted
inserted
replaced
11401:306b976d73bf | 11402:66d935214d8e |
---|---|
731 if (decoded_time == 0) | 731 if (decoded_time == 0) |
732 list_args[8] = Qnil; | 732 list_args[8] = Qnil; |
733 else | 733 else |
734 XSETINT (list_args[8], difftm (&save_tm, decoded_time)); | 734 XSETINT (list_args[8], difftm (&save_tm, decoded_time)); |
735 return Flist (9, list_args); | 735 return Flist (9, list_args); |
736 } | |
737 | |
738 DEFUN ("encode-time", Fencode_time, Sencode_time, 6, 7, 0, | |
739 "Convert SEC, MIN, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\ | |
740 This is the reverse operation of `decode-time', which see. ZONE defaults | |
741 to the current time zone and daylight savings time if not specified; if | |
742 specified, it can be either a list (as from `current-time-zone') or an | |
743 integer (as from `decode-time'), and is applied without consideration for | |
744 daylight savings time. If YEAR is less than 100, values in the range 0 to | |
745 37 are interpreted as in the 21st century, all other values arein the 20th | |
746 century.") | |
747 (sec, min, hour, day, month, year, zone) | |
748 Lisp_Object sec, min, hour, day, month, year, zone; | |
749 { | |
750 double universal; | |
751 int fullyear, mon; | |
752 static char days[11] = { 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 }; | |
753 | |
754 CHECK_NATNUM (sec, 0); | |
755 CHECK_NATNUM (min, 1); | |
756 CHECK_NATNUM (hour, 2); | |
757 CHECK_NATNUM (day, 3); | |
758 CHECK_NATNUM (month, 4); | |
759 CHECK_NATNUM (year, 5); | |
760 | |
761 fullyear = XINT (year); | |
762 if (fullyear < 100) | |
763 { | |
764 if (fullyear < 38) /* end of time: 2038-01-19 03:14:08 */ | |
765 fullyear += 2000; | |
766 else | |
767 fullyear += 1900; | |
768 } | |
769 | |
770 if (NILP (zone)) | |
771 zone = Fcurrent_time_zone (Qnil); | |
772 if (CONSP (zone)) | |
773 zone = Fcar (zone); | |
774 | |
775 CHECK_NUMBER (zone, 6); | |
776 | |
777 /* all of these should evaluate to compile-time constants. */ | |
778 #define MIN 60.0 /* 60 */ | |
779 #define HOUR (60*MIN) /* 3600 */ | |
780 #define DAY (24*HOUR) /* 86400 */ | |
781 #define YEAR (365*DAY) /* 31536000 */ | |
782 #define YEAR4 (4*YEAR+DAY) /* 126230400 */ | |
783 #define YEAR100 (25*YEAR4-DAY) /* 3155673600 */ | |
784 #define YEAR400 (4*YEAR100+DAY) /* 12622780800 */ | |
785 #define YEAR1900 (4*YEAR400+3*YEAR100) /* 59958144000 */ | |
786 #define YEAR1970 (YEAR1900+17*YEAR4+2*YEAR) /* 62167132800 */ | |
787 #define LEAPBIAS (59*DAY) /* 5097600 */ | |
788 | |
789 mon = XINT (month) - 1; | |
790 fullyear--; | |
791 mon += 10; | |
792 fullyear += mon/12; | |
793 mon %= 12; | |
794 | |
795 universal = XINT (sec) + XINT (min) * MIN + XINT (hour) * HOUR; | |
796 while (mon-- > 0) | |
797 universal += days[mon] * DAY; | |
798 universal += (XINT (day) - 1) * DAY; | |
799 universal += YEAR400 * (fullyear/400); | |
800 fullyear %= 400; | |
801 universal += YEAR100 * (fullyear/100); | |
802 fullyear %= 100; | |
803 universal += YEAR4 * (fullyear/4); | |
804 fullyear %= 4; | |
805 universal += YEAR * fullyear; | |
806 universal -= YEAR1970 - LEAPBIAS; | |
807 | |
808 return make_time ((int)(universal - XINT (zone))); | |
809 | |
810 #undef MIN | |
811 #undef HOUR | |
812 #undef DAY | |
813 #undef YEAR | |
814 #undef YEAR4 | |
815 #undef YEAR100 | |
816 #undef YEAR400 | |
817 #undef YEAR1900 | |
818 #undef YEAR1970 | |
819 #undef LEAPBIAS | |
736 } | 820 } |
737 | 821 |
738 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, | 822 DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, |
739 "Return the current time, as a human-readable string.\n\ | 823 "Return the current time, as a human-readable string.\n\ |
740 Programs can use this function to decode a time,\n\ | 824 Programs can use this function to decode a time,\n\ |
2231 defsubr (&Suser_full_name); | 2315 defsubr (&Suser_full_name); |
2232 defsubr (&Semacs_pid); | 2316 defsubr (&Semacs_pid); |
2233 defsubr (&Scurrent_time); | 2317 defsubr (&Scurrent_time); |
2234 defsubr (&Sformat_time_string); | 2318 defsubr (&Sformat_time_string); |
2235 defsubr (&Sdecode_time); | 2319 defsubr (&Sdecode_time); |
2320 defsubr (&Sencode_time); | |
2236 defsubr (&Scurrent_time_string); | 2321 defsubr (&Scurrent_time_string); |
2237 defsubr (&Scurrent_time_zone); | 2322 defsubr (&Scurrent_time_zone); |
2238 defsubr (&Ssystem_name); | 2323 defsubr (&Ssystem_name); |
2239 defsubr (&Smessage); | 2324 defsubr (&Smessage); |
2240 defsubr (&Smessage_box); | 2325 defsubr (&Smessage_box); |