Index | Thread | Search

From:
enh <enh@google.com>
Subject:
strptime: %v
To:
OpenBSD Tech <tech@openbsd.org>
Date:
Tue, 26 Aug 2025 16:38:29 -0400

Download raw body.

Thread
  • enh:

    strptime: %v

strftime() supports %v, so folks expect strptime() to do so too. this
one isn't a GNU extension, and just matches the openbsd strftime().

diff --git a/lib/libc/time/strptime.3 b/lib/libc/time/strptime.3
index 58c7cc21968..d6669d2672d 100644
--- a/lib/libc/time/strptime.3
+++ b/lib/libc/time/strptime.3
@@ -165,6 +165,8 @@ .Sh DESCRIPTION
 If it has fewer than four days in the new year, then it is considered
 the last week of the previous year.
 Weeks are numbered from 1 to 53.
+.It Cm \&%v
+the date as %e-%b-%Y.
 .It Cm \&%w
 the weekday as a decimal number [0,6], with 0 representing Sunday;
 leading zeros are permitted but not required.
diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c
index 2fae1f49220..4ae645d326d 100644
--- a/lib/libc/time/strptime.c
+++ b/lib/libc/time/strptime.c
@@ -184,6 +184,12 @@ literal:
  return (NULL);
  break;

+ case 'v': /* The date as "%e-%b-%Y". */
+ _LEGAL_ALT(0);
+ if (!(bp = _strptime(bp, "%e-%b-%Y", tm, 0)))
+ return (NULL);
+ break;
+
  case 'X': /* The time, using the locale's format. */
  _LEGAL_ALT(_ALT_E);
  if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0)))
diff --git a/lib/libc/time/strptime.3 b/lib/libc/time/strptime.3
index 58c7cc21968..d6669d2672d 100644
--- a/lib/libc/time/strptime.3
+++ b/lib/libc/time/strptime.3
@@ -165,6 +165,8 @@ .Sh DESCRIPTION
 If it has fewer than four days in the new year, then it is considered
 the last week of the previous year.
 Weeks are numbered from 1 to 53.
+.It Cm \&%v
+the date as %e-%b-%Y.
 .It Cm \&%w
 the weekday as a decimal number [0,6], with 0 representing Sunday;
 leading zeros are permitted but not required.
diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c
index 2fae1f49220..4ae645d326d 100644
--- a/lib/libc/time/strptime.c
+++ b/lib/libc/time/strptime.c
@@ -184,6 +184,12 @@ literal:
 				return (NULL);
 			break;
 
+		case 'v':	/* The date as "%e-%b-%Y". */
+			_LEGAL_ALT(0);
+			if (!(bp = _strptime(bp, "%e-%b-%Y", tm, 0)))
+				return (NULL);
+			break;
+
 		case 'X':	/* The time, using the locale's format. */
 			_LEGAL_ALT(_ALT_E);
 			if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0)))