+
+ /* Now we have parsed all the information except the date format
+ which depends on whether the clock is being set or read */
+
+ time(&tm);
+ memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
+ /* Zero out fields - take her back to midnight! */
+ if (date_str != NULL) {
+ tm_time.tm_sec = 0;
+ tm_time.tm_min = 0;
+ tm_time.tm_hour = 0;
+ }
+
+ /* Process any date input to UNIX time since 1 Jan 1970 */
+ if (date_str != NULL) {
+
+ if (strchr(date_str, ':') != NULL) {
+ date_conv_ftime(&tm_time, date_str);
+ } else {
+ date_conv_time(&tm_time, date_str);
+ }
+
+ /* Correct any day of week and day of year etc fields */
+ tm = mktime(&tm_time);
+ if (tm < 0)
+ fatalError(invalid_date, "date", date_str);
+
+ /* if setting time, set it */
+ if (set_time) {
+ if (stime(&tm) < 0) {
+ fatalError("date: can't set date.\n");
+ }
+ }
+ }
+
+ /* Display output */
+
+ /* Deal with format string */
+ if (date_fmt == NULL) {
+ date_fmt = (rfc822
+ ? (utc
+ ? "%a, %_d %b %Y %H:%M:%S GMT"
+ : "%a, %_d %b %Y %H:%M:%S %z")
+ : "%a %b %e %H:%M:%S %Z %Y");
+
+ } else if (*date_fmt == '\0') {
+ /* Imitate what GNU 'date' does with NO format string! */
+ printf("\n");
+ exit(TRUE);
+ }
+
+ /* Handle special conversions */
+
+ if (strncmp(date_fmt, "%f", 2) == 0) {
+ date_fmt = "%Y.%m.%d-%H:%M:%S";
+ }
+
+ /* Print OUTPUT (after ALL that!) */
+ t_buff = xmalloc(201);
+ strftime(t_buff, 200, date_fmt, &tm_time);
+ printf("%s\n", t_buff);
+
+ return(TRUE);