diff options
| author | Richard M. Stallman | 1995-04-12 06:16:00 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-04-12 06:16:00 +0000 |
| commit | cce7b8a03846872cbf9b41a3585536a6860df840 (patch) | |
| tree | d3e02f53233253cce0021e4de7c04f0b1d2026d3 /src | |
| parent | 359628006351ee344a71819ff445d22163f341d8 (diff) | |
| download | emacs-cce7b8a03846872cbf9b41a3585536a6860df840.tar.gz emacs-cce7b8a03846872cbf9b41a3585536a6860df840.zip | |
(Fencode_time): Use XINT to examine `zone'.
(Fencode_time): New function, to match `decode-time'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/editfns.c b/src/editfns.c index b08ac4c5d0b..30357d59d85 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -735,6 +735,90 @@ ZONE is an integer indicating the number of seconds east of Greenwich.\n\ | |||
| 735 | return Flist (9, list_args); | 735 | return Flist (9, list_args); |
| 736 | } | 736 | } |
| 737 | 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 | ||
| 820 | } | ||
| 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\ |
| @@ -2233,6 +2317,7 @@ syms_of_editfns () | |||
| 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); |