annotate src/strftime.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 74fd4e045ea6
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* strftime - custom formatting of date and/or time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 along with this program; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Note: this version of strftime lacks locale support,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 but it is standalone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 Performs `%' substitutions similar to those in printf. Except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 where noted, substituted fields have a fixed size; numeric fields are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 padded if necessary. Padding is with zeros by default; for fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 that display a single number, padding can be changed or inhibited by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 following the `%' with one of the modifiers described below. Unknown
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 field specifiers are copied as normal characters. All other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 characters are copied to the output without change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 Supports a superset of the ANSI C field specifiers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Literal character fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 % %
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 n newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 t tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Numeric modifiers (a nonstandard extension):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 - do not pad the field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 _ pad the field with spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 Time fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 %H hour (00..23)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 %I hour (01..12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 %k hour ( 0..23)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 %l hour ( 1..12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 %M minute (00..59)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 %p locale's AM or PM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 %r time, 12-hour (hh:mm:ss [AP]M)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 %R time, 24-hour (hh:mm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 %S second (00..61)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 %T time, 24-hour (hh:mm:ss)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 %X locale's time representation (%H:%M:%S)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 %Z time zone (EDT), or nothing if no time zone is determinable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 Date fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 %a locale's abbreviated weekday name (Sun..Sat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 %A locale's full weekday name, variable length (Sunday..Saturday)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 %b locale's abbreviated month name (Jan..Dec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 %B locale's full month name, variable length (January..December)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 %c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 %C century (00..99)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 %d day of month (01..31)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 %e day of month ( 1..31)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 %D date (mm/dd/yy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 %h same as %b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 %j day of year (001..366)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 %m month (01..12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 %U week number of year with Sunday as first day of week (00..53)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 %w day of week (0..6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 %W week number of year with Monday as first day of week (00..53)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 %x locale's date representation (mm/dd/yy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 %y last two digits of year (00..99)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 %Y year (1970...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 David MacKenzie <djm@gnu.ai.mit.edu> */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #ifdef HAVE_CONFIG_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 #if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 #include <sys/time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #include <time.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 #ifndef STDC_HEADERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 time_t mktime ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
97 #if defined(WIN32_NATIVE) || defined(CYGWIN)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 0
diff changeset
98 #include <time.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 0
diff changeset
99 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #if defined(HAVE_TZNAME)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 extern char *tzname[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #endif
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
103 #endif /* WIN32_NATIVE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #define strftime emacs_strftime
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 /* Types of padding for numbers in date and time. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 enum padding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 none, blank, zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
115 static char const* const days[] =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
120 static char const * const months[] =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 "January", "February", "March", "April", "May", "June",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "July", "August", "September", "October", "November", "December"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 /* Add character C to STRING and increment LENGTH,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 unless LENGTH would exceed MAX. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #define add_char(c) do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (length + 1 <= max) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 string[length++] = (c); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 /* Add a 2 digit number to STRING, padding if specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 Return the number of characters added, up to MAX. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 add_num2 (char *string, int num, int max, enum padding pad)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 int top = num / 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 int length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 if (top == 0 && pad == blank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 add_char (' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 else if (top != 0 || pad == zero)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 add_char (top + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 add_char (num % 10 + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 return length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 /* Add a 3 digit number to STRING, padding if specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 Return the number of characters added, up to MAX. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 add_num3 (char *string, int num, int max, enum padding pad)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 int top = num / 100;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 int mid = (num - top * 100) / 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 int length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (top == 0 && pad == blank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 add_char (' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 else if (top != 0 || pad == zero)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 add_char (top + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 if (mid == 0 && top == 0 && pad == blank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 add_char (' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 else if (mid != 0 || top != 0 || pad == zero)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 add_char (mid + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 add_char (num % 10 + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 return length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 /* Like strncpy except return the number of characters copied. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
177 add_str (char *to, const char *from, int max)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 for (i = 0; from[i] && i <= max; ++i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 to[i] = from[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 return i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 add_num_time_t (char *string, int max, time_t num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 /* This buffer is large enough to hold the character representation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (including the trailing NUL) of any unsigned decimal quantity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 whose binary representation fits in 128 bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 char buf[40];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 if (sizeof (num) > 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 sprintf (buf, "%lu", (unsigned long) num);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 length = add_str (string, buf, max);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 return length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 /* Return the week in the year of the time in TM, with the weeks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 starting on Sundays. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
206 sun_week (const struct tm *tm)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 int dl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 /* Set `dl' to the day in the year of the last day of the week previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 to the one containing the day specified in TM. If the day specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 in TM is in the first week of the year, `dl' will be negative or 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 Otherwise, calculate the number of complete weeks before our week
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (dl / 7) and add any partial week at the start of the year (dl % 7). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 dl = tm->tm_yday - tm->tm_wday;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /* Return the week in the year of the time in TM, with the weeks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 starting on Mondays. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
223 mon_week (const struct tm *tm)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 int dl, wday;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if (tm->tm_wday == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 wday = 6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 wday = tm->tm_wday - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 dl = tm->tm_yday - wday;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 #if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
236 char *zone_name (const struct tm *tp);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 char *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
238 zone_name (const struct tm *tp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 char *timezone ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 struct timeval tv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 struct timezone tz;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 gettimeofday (&tv, &tz);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 return timezone (tz.tz_minuteswest, tp->tm_isdst);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 /* Format the time given in TM according to FORMAT, and put the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 results in STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 Return the number of characters (not including terminating null)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 that were put into STRING, or 0 if the length would have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 exceeded MAX. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
255 size_t strftime (char *string, size_t max, const char *format,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
256 const struct tm *tm);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 size_t
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
259 strftime (char *string, size_t max, const char *format, const struct tm *tm)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 enum padding pad; /* Type of padding to apply. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 size_t length = 0; /* Characters put in STRING so far. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 for (; *format && length < max; ++format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 if (*format != '%')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 add_char (*format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ++format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 /* Modifiers: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 if (*format == '-')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 pad = none;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ++format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 else if (*format == '_')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 pad = blank;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ++format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 pad = zero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 switch (*format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 /* Literal character fields: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 case 0:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 case '%':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 add_char ('%');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 case 'n':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 add_char ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 case 't':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 add_char ('\t');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 add_char (*format);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 /* Time fields: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 case 'H':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 case 'k':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 add_num2 (&string[length], tm->tm_hour, max - length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 *format == 'H' ? pad : blank);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 case 'I':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 case 'l':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 int hour12;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (tm->tm_hour == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 hour12 = 12;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 else if (tm->tm_hour > 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 hour12 = tm->tm_hour - 12;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 hour12 = tm->tm_hour;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 add_num2 (&string[length], hour12, max - length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 *format == 'I' ? pad : blank);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 case 'M':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 add_num2 (&string[length], tm->tm_min, max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 case 'p':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 if (tm->tm_hour < 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 add_char ('A');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 add_char ('P');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 add_char ('M');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 case 'r':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 strftime (&string[length], max - length, "%I:%M:%S %p", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 case 'R':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 strftime (&string[length], max - length, "%H:%M", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 case 's':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 struct tm writable_tm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 writable_tm = *tm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 length += add_num_time_t (&string[length], max - length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 mktime (&writable_tm));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 case 'S':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 add_num2 (&string[length], tm->tm_sec, max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 case 'T':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 strftime (&string[length], max - length, "%H:%M:%S", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 case 'X':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 strftime (&string[length], max - length, "%H:%M:%S", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 case 'Z':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #ifdef HAVE_TM_ZONE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 length += add_str (&string[length], tm->tm_zone, max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 #ifdef HAVE_TZNAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 if (tm->tm_isdst && tzname[1] && *tzname[1])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 length += add_str (&string[length], tzname[1], max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 length += add_str (&string[length], tzname[0], max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 length += add_str (&string[length], zone_name (tm), max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 /* Date fields: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 case 'a':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 add_char (days[tm->tm_wday][0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 add_char (days[tm->tm_wday][1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 add_char (days[tm->tm_wday][2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 case 'A':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 add_str (&string[length], days[tm->tm_wday], max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 case 'b':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 case 'h':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 add_char (months[tm->tm_mon][0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 add_char (months[tm->tm_mon][1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 add_char (months[tm->tm_mon][2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 case 'B':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 add_str (&string[length], months[tm->tm_mon], max - length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 case 'c':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 strftime (&string[length], max - length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 "%a %b %d %H:%M:%S %Z %Y", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 case 'C':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 add_num2 (&string[length], (tm->tm_year + 1900) / 100,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 case 'd':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 add_num2 (&string[length], tm->tm_mday, max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 case 'e':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 add_num2 (&string[length], tm->tm_mday, max - length, blank);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 case 'D':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 strftime (&string[length], max - length, "%m/%d/%y", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 case 'j':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 add_num3 (&string[length], tm->tm_yday + 1, max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 case 'm':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 add_num2 (&string[length], tm->tm_mon + 1, max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 case 'U':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 add_num2 (&string[length], sun_week (tm), max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 case 'w':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 add_char (tm->tm_wday + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 case 'W':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 add_num2 (&string[length], mon_week (tm), max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 case 'x':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 strftime (&string[length], max - length, "%m/%d/%y", tm);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 case 'y':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 add_num2 (&string[length], tm->tm_year % 100,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 max - length, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 case 'Y':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 add_char ((tm->tm_year + 1900) / 1000 + '0');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 length +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 add_num3 (&string[length],
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (1900 + tm->tm_year) % 1000, max - length, zero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 add_char (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 return length - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 }