Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/time.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/time.c
r3232 r3621 24 24 &ptm->tm_hour, 25 25 &ptm->tm_min, 26 &end) >= 2) { 26 &end) >= 2 27 ) { 27 28 /* no adjustments needed */ 28 29 } else … … 31 32 &ptm->tm_mon, &ptm->tm_mday, 32 33 &ptm->tm_hour, &ptm->tm_min, 33 &end) >= 4) { 34 &end) >= 4 35 ) { 34 36 /* Adjust month from 1-12 to 0-11 */ 35 37 ptm->tm_mon -= 1; … … 39 41 &ptm->tm_mon, &ptm->tm_mday, 40 42 &ptm->tm_hour, &ptm->tm_min, 41 &end) >= 5) { 42 ptm->tm_year -= 1900; /* Adjust years */ 43 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 44 } else 43 &end) >= 5 45 44 /* yyyy-mm-dd HH:MM */ 46 if (sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year,45 || sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year, 47 46 &ptm->tm_mon, &ptm->tm_mday, 48 47 &ptm->tm_hour, &ptm->tm_min, 49 &end) >= 5) { 48 &end) >= 5 49 ) { 50 50 ptm->tm_year -= 1900; /* Adjust years */ 51 51 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ … … 59 59 } else 60 60 #endif 61 //TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes)62 61 { 63 62 bb_error_msg_and_die(bb_msg_invalid_date, date_str); … … 69 68 /* else end != NUL and we error out */ 70 69 } 71 } else if (date_str[0] == '@') { 70 } else 71 if (strchr(date_str, '-') 72 /* Why strchr('-') check? 73 * sscanf below will trash ptm->tm_year, this breaks 74 * if parse_str is "10101010" (iow, "MMddhhmm" form) 75 * because we destroy year. Do these sscanf 76 * only if we saw a dash in parse_str. 77 */ 78 /* yyyy-mm-dd HH */ 79 && (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year, 80 &ptm->tm_mon, &ptm->tm_mday, 81 &ptm->tm_hour, 82 &end) >= 4 83 /* yyyy-mm-dd */ 84 || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year, 85 &ptm->tm_mon, &ptm->tm_mday, 86 &end) >= 3 87 ) 88 ) { 89 ptm->tm_year -= 1900; /* Adjust years */ 90 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 91 } else 92 if (date_str[0] == '@') { 72 93 time_t t = bb_strtol(date_str + 1, NULL, 10); 73 94 if (!errno) { … … 166 187 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 167 188 } 189 ptm->tm_sec = 0; /* assume zero if [.SS] is not given */ 168 190 if (end == '.') { 169 191 /* xxx.SS */ … … 188 210 } 189 211 212 static char* strftime_fmt(char *buf, unsigned len, time_t *tp, const char *fmt) 213 { 214 time_t t; 215 if (!tp) { 216 tp = &t; 217 time(tp); 218 } 219 /* Returns pointer to NUL */ 220 return buf + strftime(buf, len, fmt, localtime(tp)); 221 } 222 223 char* FAST_FUNC strftime_HHMMSS(char *buf, unsigned len, time_t *tp) 224 { 225 return strftime_fmt(buf, len, tp, "%H:%M:%S"); 226 } 227 228 char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) 229 { 230 return strftime_fmt(buf, len, tp, "%Y-%m-%d %H:%M:%S"); 231 } 232 190 233 #if ENABLE_MONOTONIC_SYSCALL 191 234
Note:
See TracChangeset
for help on using the changeset viewer.