"touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
"20120123-123400.000000000\n" "" ""
+# Yes, the year could roll over while you're running this test. I do not care.
+testing "-t MMDDhhmm" \
+ "touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
+ "$(date +%Y)-01-23:12-34-00\n" "" ""
+
+testing "-t YYMMDDhhmm" \
+ "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
+ "$(date +%C)21-01-23:12-34-00\n" "" ""
+
+testing "-t CCYYMMDDhhmm" \
+ "touch -t 201201231234 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
+ "20120123-123400.000000000\n" "" ""
+
testing "-t seconds" \
"touch -t 201201231234.56 walrus && date -r walrus +%Y%m%d-%H%M%S.%N" \
"20120123-123456.000000000\n" "" ""
"touch -d 2009-02-13T23:31:30Z walrus && date -r walrus +%s" \
"1234567890\n" "" ""
+testing "-d with space" \
+ "touch -d '2009-02-13 23:31:30Z' walrus && date -r walrus +%s" \
+ "1234567890\n" "" ""
+
testing "-d nanoseconds" \
"touch -d 2009-02-13T23:31:30.123456789Z walrus && date -r walrus +%s.%N" \
"1234567890.123456789\n" "" ""
"touch -t 01231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
"$(date +%Y)-01-23:12-34-00\n" "" ""
+testing "-t CCMMDDhhmm" \
+ "touch -t 2101231234 input && date +%Y-%m-%d:%H-%M-%S -r input" \
+ "$(date +%C)21-01-23:12-34-00\n" "" ""
+
+
#testing "-a"
#testing "-m"
#testing "-am"
format = (char *[]){"%Y-%m-%dT%T", "%Y-%m-%d %T", 0};
date = TT.date;
} else {
- format = (char *[]){"%Y%m%d%H%M", "%m%d%H%M", "%y%m%d%H%M", 0};
+ format = (char *[]){"%m%d%H%M", "%y%m%d%H%M", "%C%y%m%d%H%M", 0};
date = TT.time;
}
}
while (*format) {
+ if (toys.optflags&FLAG_t) {
+ s = strchr(date, '.');
+ if ((s ? s-date : strlen(date)) != strlen(*format)) {
+ format++;
+ continue;
+ }
+ }
localtime_r(&(ts->tv_sec), &tm);
// Adjusting for daylight savings time gives the wrong answer.
tm.tm_isdst = 0;