date formats acceptable to the "date" command

Denys Vlasenko vda.linux at googlemail.com
Mon Jan 17 13:07:38 UTC 2011


On Mon, Jan 17, 2011 at 12:16 PM, David Collier
<from_busybox_maillist at dexdyne.com> wrote:
> Walter,
>
> Denys
>
> So the posix spec is the one that has recently been deleted. I guess that
> enhances the argument for supporting it.

I looked at the code more closely and guess what? It is _already_ supported:

coreutils/date.c:

        if (!(opt & (OPT_SET | OPT_DATE))) {
                opt |= OPT_SET;
                date_str = argv[0]; /* can be NULL */
                if (date_str) {
#if ENABLE_FEATURE_DATE_COMPAT
                        int len = strspn(date_str, "0123456789");
                        if (date_str[len] == '\0'
                         || (date_str[len] == '.'
                            && isdigit(date_str[len+1])
                            && isdigit(date_str[len+2])
                            && date_str[len+3] == '\0'
                            )
                        ) {
                                /* Dreaded MMDDhhmm[[CC]YY][.ss] format!
                                 * It does not match -d or -s format.
                                 * Some users actually do use it.
                                 */
                                len -= 8;
                                if (len < 0 || len > 4 || (len & 1))

bb_error_msg_and_die(bb_msg_invalid_date, date_str);
                                if (len != 0) { /* move YY or CCYY to front */
                                        char buf[4];
                                        memcpy(buf, date_str + 8, len);
                                        memmove(date_str + len, date_str, 8);
                                        memcpy(date_str, buf, len);
                                }
                        }
#endif
                        argv++;
                }
        }

I just checked: it is present in 1.18.x releases and seems to work.
I added
bb_error_msg_and_die("date_str:'%s'", date_str);
just above #endif and I see the following:

$ ./busybox date 112201022134.03
date: date_str:'213411220102.03'

$ ./busybox date 112201022134
date: date_str:'213411220102'

$ ./busybox date 1122010234
date: date_str:'3411220102'

What is the problem?

-- 
vda


More information about the busybox mailing list