diff --git a/lib/libc/stdtime/strftime.3 b/lib/libc/stdtime/strftime.3 index a2e17d9b0b28..3f50c6b964d4 100644 --- a/lib/libc/stdtime/strftime.3 +++ b/lib/libc/stdtime/strftime.3 @@ -85,25 +85,17 @@ as follows:- is replaced by national representation of the full weekday name. .It Cm %a is replaced by national representation of -the abbreviated weekday name, where the abbreviation -is the first three characters. +the abbreviated weekday name. .It Cm \&%B is replaced by national representation of the full month name. .It Cm %b is replaced by national representation of -the abbreviated month name, where the abbreviation is -the first three characters. +the abbreviated month name. .It Cm \&%C is replaced by (year / 100) as decimal number; single digits are preceded by a zero. .It Cm %c is replaced by national representation of time and date. -The format is similar to that produced by -.Xr ctime 3 -and is -equivalent to "%a %Ef %T %Y". -It also implies the -"3+1+6+1+8+1+4" format of output. .It Cm \&%D is equivalent to .Dq Li %m/%d/%y . @@ -126,6 +118,9 @@ and %OB to represent alternative months names .It Cm %e is replaced by the day of month as a decimal number (1-31); single digits are preceded by a blank. +.It Cm \&%F +is equivalent to +.Dq Li %Y-%m-%d . .It Cm \&%G is replaced by a year as a decimal number with century. This year is the one that contains the greater part of diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index e54ea893a0a4..a4cdc86a51f8 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -123,7 +123,6 @@ label: "%02d", pt, ptlim); continue; case 'c': - /* NOTE: c_fmt is hardcoded in timelocal.c */ pt = _fmt(tptr->c_fmt, t, pt, ptlim); continue; case 'D': @@ -162,12 +161,17 @@ label: case 'f': if (!Ealternative) break; - pt = _fmt(tptr->Ef_fmt, t, pt, ptlim); + pt = _fmt(*(tptr->md_order) == 'd' ? + "%e %b" : "%b %e", + t, pt, ptlim); continue; case 'F': if (!Ealternative) - break; - pt = _fmt(tptr->EF_fmt, t, pt, ptlim); + pt = _fmt("%Y-%m-%d", t, pt, ptlim); + else + pt = _fmt(*(tptr->md_order) == 'd' ? + "%e %B" : "%B %e", + t, pt, ptlim); continue; case 'H': pt = _conv(t->tm_hour, "%02d", pt, ptlim); diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 58ae5170d332..b39176dc12b9 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -141,7 +141,6 @@ label: break; case 'c': - /* NOTE: c_fmt is hardcoded in timelocal.c */ buf = _strptime(buf, tptr->c_fmt, tm); if (buf == 0) return 0; @@ -166,10 +165,22 @@ label: goto label; case 'F': + if (!Ealternative) + buf = _strptime(buf, "%Y-%m-%d", tm); + else + buf = _strptime(buf, + *(tptr->md_order) == 'd' ? + "%e %B" : "%B %e", tm); + if (buf == 0) + return 0; + break; + case 'f': if (!Ealternative) break; - buf = _strptime(buf, (c == 'f') ? tptr->Ef_fmt : tptr->EF_fmt, tm); + buf = _strptime(buf, + *(tptr->md_order) == 'd' ? "%e %b" : "%b %e", + tm); if (buf == 0) return 0; break; diff --git a/lib/libc/stdtime/timelocal.c b/lib/libc/stdtime/timelocal.c index 1caed7d474f6..133db4c2dfc6 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -36,9 +36,7 @@ static struct lc_time_T _time_locale; static int _time_using_locale; static char * time_locale_buf; -#define LCTIME_SIZE_FULL (sizeof(struct lc_time_T) / sizeof(char *)) -#define LCTIME_SIZE_MIN \ - (offsetof(struct lc_time_T, ampm_fmt) / sizeof(char *)) +#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) static const struct lc_time_T _C_time_locale = { { @@ -70,7 +68,7 @@ static const struct lc_time_T _C_time_locale = { /* ** c_fmt (ctime-compatible) */ - "%a %Ef %T %Y", + "%a %b %e %T %Y", /* am */ "AM", @@ -79,22 +77,20 @@ static const struct lc_time_T _C_time_locale = { "PM", /* date_fmt */ - "%a %Ef %X %Z %Y", + "%a %b %e %X %Z %Y", + /* alt_month + ** Standalone motnhs forms for %OB + */ { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }, - /* Ef_fmt - ** To determine short months / day order + /* md_order + ** Month / day order in dates */ - "%b %e", - - /* EF_fmt - ** To determine long months / day order - */ - "%B %e", + "md", /* ampm_fmt ** To determine 12-hour clock format time (empty, if N/A) @@ -114,15 +110,10 @@ __time_load_locale(const char *name) { int ret; - _time_locale.ampm_fmt = _C_time_locale.ampm_fmt; - ret = __part_load_locale(name, &_time_using_locale, time_locale_buf, "LC_TIME", - LCTIME_SIZE_FULL, LCTIME_SIZE_MIN, + LCTIME_SIZE, LCTIME_SIZE, (const char **)&_time_locale); - /* XXX: always overwrite for ctime format parsing compatibility */ - _time_locale.c_fmt = _C_time_locale.c_fmt; - return (ret); } diff --git a/lib/libc/stdtime/timelocal.h b/lib/libc/stdtime/timelocal.h index 7dbfdcfb019b..843c42b47803 100644 --- a/lib/libc/stdtime/timelocal.h +++ b/lib/libc/stdtime/timelocal.h @@ -45,8 +45,7 @@ struct lc_time_T { const char * pm; const char * date_fmt; const char * alt_month[12]; - const char * Ef_fmt; - const char * EF_fmt; + const char * md_order; const char * ampm_fmt; };