aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-07-30 23:11:00 +0000
committerRobert Griebl <griebl@gmx.de>2002-07-30 23:11:00 +0000
commitdf03932b7e933f0f5f55aad24fac3b9d531dc4a1 (patch)
tree08482ae8240326db062a335d5363a672e78e3b3e
parent70112da81a5591d345dc7e8c9fd23e4e8bb67d17 (diff)
downloadbusybox-w32-df03932b7e933f0f5f55aad24fac3b9d531dc4a1.tar.gz
busybox-w32-df03932b7e933f0f5f55aad24fac3b9d531dc4a1.tar.bz2
busybox-w32-df03932b7e933f0f5f55aad24fac3b9d531dc4a1.zip
Added the -I (isofmt) options to date, which comes in handy for scripts
(this is a confiureable option)
-rw-r--r--coreutils/date.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index 41ceee29d..4bd308b86 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -138,8 +138,15 @@ int date_main(int argc, char **argv)
138 time_t tm; 138 time_t tm;
139 struct tm tm_time; 139 struct tm tm_time;
140 140
141#ifdef CONFIG_FEATURE_DATE_ISOFMT
142 int ifmt = 0;
143#define GETOPT_ISOFMT "I::"
144#else
145#define GETOPT_ISOFMT
146#endif
147
141 /* Interpret command line args */ 148 /* Interpret command line args */
142 while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) { 149 while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT )) != EOF) {
143 switch (c) { 150 switch (c) {
144 case 'R': 151 case 'R':
145 rfc822 = 1; 152 rfc822 = 1;
@@ -160,11 +167,31 @@ int date_main(int argc, char **argv)
160 if ((date_str != NULL) || ((date_str = optarg) == NULL)) 167 if ((date_str != NULL) || ((date_str = optarg) == NULL))
161 show_usage(); 168 show_usage();
162 break; 169 break;
170#ifdef CONFIG_FEATURE_DATE_ISOFMT
171 case 'I':
172 if ( !optarg )
173 ifmt = 1;
174 else {
175 int ifmt_len = xstrlen ( optarg );
176
177 if (( ifmt_len <= 4 ) && ( strncmp ( optarg, "date", ifmt_len ) == 0 ))
178 ifmt = 1;
179 else if (( ifmt_len <= 5 ) && ( strncmp ( optarg, "hours", ifmt_len ) == 0 ))
180 ifmt = 2;
181 else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "minutes", ifmt_len ) == 0 ))
182 ifmt = 3;
183 else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "seconds", ifmt_len ) == 0 ))
184 ifmt = 4;
185 }
186 if ( ifmt )
187 break; // else show_usage();
188#endif
163 default: 189 default:
164 show_usage(); 190 show_usage();
165 } 191 }
166 } 192 }
167 193
194
168 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) 195 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
169 date_fmt = &argv[optind][1]; /* Skip over the '+' */ 196 date_fmt = &argv[optind][1]; /* Skip over the '+' */
170 else if (date_str == NULL) { 197 else if (date_str == NULL) {
@@ -220,12 +247,33 @@ int date_main(int argc, char **argv)
220 247
221 /* Deal with format string */ 248 /* Deal with format string */
222 if (date_fmt == NULL) { 249 if (date_fmt == NULL) {
223 date_fmt = (rfc822 250#ifdef CONFIG_FEATURE_DATE_ISOFMT
224 ? (utc 251 switch ( ifmt ) {
225 ? "%a, %e %b %Y %H:%M:%S GMT" 252 case 4:
226 : "%a, %e %b %Y %H:%M:%S %z") 253 date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z";
227 : "%a %b %e %H:%M:%S %Z %Y"); 254 break;
228 255 case 3:
256 date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z";
257 break;
258 case 2:
259 date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z";
260 break;
261 case 1:
262 date_fmt = "%Y-%m-%d";
263 break;
264 case 0:
265 default:
266#endif
267 date_fmt = (rfc822
268 ? (utc
269 ? "%a, %e %b %Y %H:%M:%S GMT"
270 : "%a, %e %b %Y %H:%M:%S %z")
271 : "%a %b %e %H:%M:%S %Z %Y");
272
273#ifdef CONFIG_FEATURE_DATE_ISOFMT
274 break;
275 }
276#endif
229 } else if (*date_fmt == '\0') { 277 } else if (*date_fmt == '\0') {
230 /* Imitate what GNU 'date' does with NO format string! */ 278 /* Imitate what GNU 'date' does with NO format string! */
231 printf("\n"); 279 printf("\n");