annotate src/strftime.c @ 5615:5f4f92a31875

Move the functionality of #'cl-macroexpand into Fmacroexpand, eval.c src/ChangeLog addition: 2011-12-22 Aidan Kehoe <kehoea@parhasard.net> * eval.c (Fmacroexpand): Rename Fmacroexpand_internal, add the functionality that used to be in #'cl-macroexpand--it makes no sense for us, and needlessly slows things down, to have two separate functions. * eval.c: * eval.c (syms_of_eval): Move byte-compile-macro-environment here, now it's used by #'macroexpand. lisp/ChangeLog addition: 2011-12-22 Aidan Kehoe <kehoea@parhasard.net> * bytecomp-runtime.el: * bytecomp-runtime.el (byte-compile-macro-environment): Moved to eval.c. * cl.el: * cl.el ('cl-macroexpand): New alias. * cl.el ('macroexpand-internal): New alias. * cl.el (cl-macroexpand): Move the functionality of this to #'macroexpand (formerly #'macroexpand-internal) in eval.c; since CL is always loaded in XEmacs, it brings nothing and slows things down to have the two functions separate.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 22 Dec 2011 12:51:03 +0000
parents 308d34e9f07d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* strftime - custom formatting of date and/or time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
4 This file is part of XEmacs.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
5
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
6 XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
7 under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
8 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
9 option) any later version.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
10
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
14 for more details.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
15
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5254
diff changeset
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
20 /* This file has been ... uhhhhh ... Mule-ized. Yeah.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
21
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
22 (Everything here is external format. This is DANGEROUS and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
23 data-lossy, but fixing it is too much of a bother now.) --ben */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 442
diff changeset
24
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Note: this version of strftime lacks locale support,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 but it is standalone.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 Performs `%' substitutions similar to those in printf. Except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 where noted, substituted fields have a fixed size; numeric fields are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 padded if necessary. Padding is with zeros by default; for fields
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 that display a single number, padding can be changed or inhibited by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 following the `%' with one of the modifiers described below. Unknown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 field specifiers are copied as normal characters. All other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 characters are copied to the output without change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 Supports a superset of the ANSI C field specifiers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Literal character fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 % %
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 n newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 t tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Numeric modifiers (a nonstandard extension):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 - do not pad the field
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 _ pad the field with spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Time fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 %H hour (00..23)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 %I hour (01..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 %k hour ( 0..23)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 %l hour ( 1..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 %M minute (00..59)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 %p locale's AM or PM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 %r time, 12-hour (hh:mm:ss [AP]M)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 %R time, 24-hour (hh:mm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 %S second (00..61)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 %T time, 24-hour (hh:mm:ss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 %X locale's time representation (%H:%M:%S)
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
60 %z time zone offset (e.g. +0530, -0800 etc)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 %Z time zone (EDT), or nothing if no time zone is determinable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Date fields:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 %a locale's abbreviated weekday name (Sun..Sat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 %A locale's full weekday name, variable length (Sunday..Saturday)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 %b locale's abbreviated month name (Jan..Dec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 %B locale's full month name, variable length (January..December)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 %c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 %C century (00..99)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 %d day of month (01..31)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 %e day of month ( 1..31)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 %D date (mm/dd/yy)
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
73 %G year corresponding to the ISO 8601 week
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
74 %g Year of the ISO 8601 week within century (00 - 99)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 %h same as %b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 %j day of year (001..366)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 %m month (01..12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 %U week number of year with Sunday as first day of week (00..53)
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
79 %V ISO 8601 week number (first week is the earliest one with Thu)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 %w day of week (0..6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 %W week number of year with Monday as first day of week (00..53)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 %x locale's date representation (mm/dd/yy)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 %y last two digits of year (00..99)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 %Y year (1970...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 David MacKenzie <djm@gnu.ai.mit.edu> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #include <sys/time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 #ifndef STDC_HEADERS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 time_t mktime ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
105 #if defined(WIN32_NATIVE) || defined(CYGWIN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #if defined(HAVE_TZNAME)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 extern char *tzname[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
111 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 #define strftime emacs_strftime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 /* Types of padding for numbers in date and time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 enum padding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 none, blank, zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
123 static char const* const days[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
128 static char const * const months[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 "January", "February", "March", "April", "May", "June",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 "July", "August", "September", "October", "November", "December"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
5254
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
134 static char const * const roman_upper[] =
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
135 {
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
136 "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
137 };
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
138
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
139 static char const * const roman_lower[] =
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
140 {
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
141 "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii"
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
142 };
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
143
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 /* Add character C to STRING and increment LENGTH,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 unless LENGTH would exceed MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 #define add_char(c) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 if (length + 1 <= max) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 string[length++] = (c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 /* Add a 2 digit number to STRING, padding if specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 Return the number of characters added, up to MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 add_num2 (char *string, int num, int max, enum padding pad)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 int top = num / 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 int length = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 if (top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 else if (top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 add_char (top + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 add_char (num % 10 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 return length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 /* Add a 3 digit number to STRING, padding if specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 Return the number of characters added, up to MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 add_num3 (char *string, int num, int max, enum padding pad)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 int top = num / 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 int mid = (num - top * 100) / 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 int length = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 if (top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 else if (top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 add_char (top + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (mid == 0 && top == 0 && pad == blank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 add_char (' ');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 else if (mid != 0 || top != 0 || pad == zero)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 add_char (mid + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 add_char (num % 10 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 return length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 /* Like strncpy except return the number of characters copied. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
195 add_str (char *to, const char *from, int max)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 for (i = 0; from[i] && i <= max; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 to[i] = from[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 return i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 add_num_time_t (char *string, int max, time_t num)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 /* This buffer is large enough to hold the character representation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (including the trailing NUL) of any unsigned decimal quantity
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 whose binary representation fits in 128 bits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 char buf[40];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 if (sizeof (num) > 16)
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 793
diff changeset
213 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 sprintf (buf, "%lu", (unsigned long) num);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
215 return add_str (string, buf, max);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 /* Return the week in the year of the time in TM, with the weeks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 starting on Sundays. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
222 sun_week (const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 int dl;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* Set `dl' to the day in the year of the last day of the week previous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 to the one containing the day specified in TM. If the day specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 in TM is in the first week of the year, `dl' will be negative or 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 Otherwise, calculate the number of complete weeks before our week
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (dl / 7) and add any partial week at the start of the year (dl % 7). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 dl = tm->tm_yday - tm->tm_wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 /* Return the week in the year of the time in TM, with the weeks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 starting on Mondays. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
239 mon_week (const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 int dl, wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 if (tm->tm_wday == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 wday = 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 wday = tm->tm_wday - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 dl = tm->tm_yday - wday;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
251 #ifndef __isleap
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
252 /* Nonzero if YEAR is a leap year (every 4 years,
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
253 except every 100th isn't, and every 400th is). */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
254 # define __isleap(year) \
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
255 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
256 #endif
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
257
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
258 /* The number of days from the first day of the first ISO week of this
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
259 year to the year day YDAY with week day WDAY. ISO weeks start on
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
260 Monday; the first ISO week has the year's first Thursday. YDAY may
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
261 be as small as YDAY_MINIMUM. */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
262 #define ISO_WEEK_START_WDAY 1 /* Monday */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
263 #define ISO_WEEK1_WDAY 4 /* Thursday */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
264 #define YDAY_MINIMUM (-366)
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
265 static int
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
266 iso_week_days (int yday, int wday)
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
267 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
268 /* Add enough to the first operand of % to make it nonnegative. */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
269 int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
270 return (yday
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
271 - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
272 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
273 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
274
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
276 char *zone_name (const struct tm *tp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
278 zone_name (const struct tm *tp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 char *timezone ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 struct timeval tv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 struct timezone tz;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 gettimeofday (&tv, &tz);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 return timezone (tz.tz_minuteswest, tp->tm_isdst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 /* Format the time given in TM according to FORMAT, and put the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 results in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 Return the number of characters (not including terminating null)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 that were put into STRING, or 0 if the length would have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 exceeded MAX. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
295 size_t strftime (char *string, size_t max, const char *format,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
296 const struct tm *tm);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 size_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
299 strftime (char *string, size_t max, const char *format, const struct tm *tm)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 enum padding pad; /* Type of padding to apply. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 size_t length = 0; /* Characters put in STRING so far. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 for (; *format && length < max; ++format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 if (*format != '%')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 add_char (*format);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 /* Modifiers: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if (*format == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 pad = none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 else if (*format == '_')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 pad = blank;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ++format;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 pad = zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 switch (*format)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 /* Literal character fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 case '%':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 add_char ('%');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 case 'n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 add_char ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 case 't':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 add_char ('\t');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 add_char (*format);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* Time fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 case 'H':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 case 'k':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 add_num2 (&string[length], tm->tm_hour, max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 *format == 'H' ? pad : blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 case 'I':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 int hour12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 if (tm->tm_hour == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 hour12 = 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 else if (tm->tm_hour > 12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 hour12 = tm->tm_hour - 12;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 hour12 = tm->tm_hour;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 add_num2 (&string[length], hour12, max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 *format == 'I' ? pad : blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 case 'M':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 add_num2 (&string[length], tm->tm_min, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 if (tm->tm_hour < 12)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 add_char ('A');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 add_char ('P');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 add_char ('M');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 strftime (&string[length], max - length, "%I:%M:%S %p", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 case 'R':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 strftime (&string[length], max - length, "%H:%M", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 case 's':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 struct tm writable_tm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 writable_tm = *tm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 length += add_num_time_t (&string[length], max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 mktime (&writable_tm));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 case 'S':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 add_num2 (&string[length], tm->tm_sec, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 case 'T':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 strftime (&string[length], max - length, "%H:%M:%S", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 break;
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
402
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
403 case 'V':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
404 case 'g':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
405 case 'G':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
406 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
407 int year = tm->tm_year + 1900;
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
408 int ndays = iso_week_days (tm->tm_yday, tm->tm_wday);
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
409
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
410 if (ndays < 0)
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
411 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
412 /* This ISO week belongs to the previous year. */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
413 year--;
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
414 ndays =
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
415 iso_week_days (tm->tm_yday + (365 + __isleap (year)),
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
416 tm->tm_wday);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
417 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
418 else
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
419 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
420 int d =
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
421 iso_week_days (tm->tm_yday - (365 + __isleap (year)),
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
422 tm->tm_wday);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
423 if (0 <= d)
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
424 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
425 /* This ISO week belongs to the next year. */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
426 year++;
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
427 ndays = d;
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
428 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
429 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
430
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
431 switch (*format)
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
432 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
433 /*
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
434 #### FIXME
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
435 We really can't assume 1000 <= year <= 9999
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
436 once time_t gets beyond 32 bits, but it's true
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
437 of the rest of the code here so get with the
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
438 program
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
439 */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
440 case 'g':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
441 length +=
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
442 add_num2 (&string[length], year % 100,
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
443 max - length, pad);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
444 break;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
445
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
446 case 'G':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
447 add_char (year / 1000 + '0');
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
448 length += add_num3 (&string[length], year % 1000,
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
449 max - length, zero);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
450 break;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
451
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
452 default:
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
453 length +=
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
454 add_num2 (&string[length], ndays / 7 + 1,
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
455 max - length, pad);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
456 break;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
457 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
458 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
459 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 case 'X':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 strftime (&string[length], max - length, "%H:%M:%S", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 break;
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
464 case 'z':
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
465 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
466 /*
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
467 #### FIXME: could use tm->tm_gmtoff if present. Since
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
468 the other code in xemacs does not do so we follow the
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
469 leaders (and don't add a autoconf macro to detect
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
470 its presence).
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
471 */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
472 long int offset;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
473 long int minutes;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
474 struct tm lt, *ut;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
475 time_t utc;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
476
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
477 lt = *tm;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
478 utc = mktime(&lt);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
479 ut = gmtime(&utc);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
480 /* assume that tm is valid so the others will be too! */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
481 assert( utc != (time_t) -1 && ut != NULL );
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
482
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
483 /* tm diff code below is based on mktime.c, glibc 2.3.2 */
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
484 {
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
485 int lt4, ut4, lt100, ut100, lt400, ut400;
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
486 int intervening_leap_days, years, ndays;
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
487
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
488 lt4 = (lt.tm_year >> 2) + (1900 >> 2) -
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
489 ! (lt.tm_year & 3);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
490 ut4 = (ut->tm_year >> 2) + (1900 >> 2) -
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
491 ! (ut->tm_year & 3);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
492 lt100 = lt4 / 25 - (lt4 % 25 < 0);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
493 ut100 = ut4 / 25 - (ut4 % 25 < 0);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
494 lt400 = lt100 >> 2;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
495 ut400 = ut100 >> 2;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
496 intervening_leap_days =
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
497 (lt4 - ut4) - (lt100 - ut100) + (lt400 - ut400);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
498 years = lt.tm_year - ut->tm_year;
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
499 ndays = (365 * years + intervening_leap_days
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
500 + (lt.tm_yday - ut->tm_yday));
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
501 offset = (60 * (60 * (24 * ndays
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4203
diff changeset
502 + (lt.tm_hour - ut->tm_hour))
4203
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
503 + (lt.tm_min - ut->tm_min))
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
504 + (lt.tm_sec - ut->tm_sec));
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
505 }
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
506
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
507 minutes = offset / ( offset < 0 ? -60 : 60 );
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
508
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
509 add_char ((offset < 0 ? '-' : '+'));
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
510
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
511 if ( minutes / 600 != 0 )
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
512 add_char (minutes / 600 + '0');
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
513 else if ( pad != none )
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
514 add_char ((pad == zero ? '0' : ' '));
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
515
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
516 length +=
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
517 add_num3 (&string[length],
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
518 ((minutes / 60 ) % 10) * 100 + (minutes % 60),
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
519 max - length, pad);
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
520 break;
0a63e5de7bdc [xemacs-hg @ 2007-10-02 19:31:30 by aidan]
aidan
parents: 2500
diff changeset
521 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 case 'Z':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 #ifdef HAVE_TM_ZONE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 length += add_str (&string[length], tm->tm_zone, max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 #ifdef HAVE_TZNAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 if (tm->tm_isdst && tzname[1] && *tzname[1])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 length += add_str (&string[length], tzname[1], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 length += add_str (&string[length], tzname[0], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 length += add_str (&string[length], zone_name (tm), max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 /* Date fields: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 case 'a':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 add_char (days[tm->tm_wday][0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 add_char (days[tm->tm_wday][1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 add_char (days[tm->tm_wday][2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 case 'A':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 add_str (&string[length], days[tm->tm_wday], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 case 'h':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 add_char (months[tm->tm_mon][0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 add_char (months[tm->tm_mon][1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 add_char (months[tm->tm_mon][2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 case 'B':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 add_str (&string[length], months[tm->tm_mon], max - length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 case 'c':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 strftime (&string[length], max - length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 "%a %b %d %H:%M:%S %Z %Y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 case 'C':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 add_num2 (&string[length], (tm->tm_year + 1900) / 100,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 case 'd':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 add_num2 (&string[length], tm->tm_mday, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 case 'e':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 add_num2 (&string[length], tm->tm_mday, max - length, blank);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 case 'D':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 strftime (&string[length], max - length, "%m/%d/%y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 case 'j':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 add_num3 (&string[length], tm->tm_yday + 1, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 case 'm':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 add_num2 (&string[length], tm->tm_mon + 1, max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 case 'U':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 add_num2 (&string[length], sun_week (tm), max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 case 'w':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 add_char (tm->tm_wday + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 case 'W':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 add_num2 (&string[length], mon_week (tm), max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 case 'x':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 strftime (&string[length], max - length, "%m/%d/%y", tm);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 case 'y':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 add_num2 (&string[length], tm->tm_year % 100,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 max - length, pad);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 case 'Y':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 add_char ((tm->tm_year + 1900) / 1000 + '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 length +=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 add_num3 (&string[length],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (1900 + tm->tm_year) % 1000, max - length, zero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 break;
5254
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
613 case '\xe6':
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
614 length +=
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
615 add_str (&string[length], roman_lower[tm->tm_mon],
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
616 max - length);
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
617 break;
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
618 case '\xC6':
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
619 length +=
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
620 add_str (&string[length], roman_upper[tm->tm_mon],
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
621 max - length);
1537701f08a1 Support Roman month numbers, #'format-time-string
Aidan Kehoe <kehoea@parhasard.net>
parents: 5016
diff changeset
622 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 add_char (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 return length - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 }