Index | Thread | Search

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

Download raw body.

Thread
%P is a strftime() extension that's "%p but in lowercase". because of
this, there's code that expects to be able to use %p and %P
interchangeably in strptime() format strings. Android has thus carried
this patch for years. (despite me forgetting to send it upstream;
sorry!)

diff --git a/lib/libc/time/strptime.3 b/lib/libc/time/strptime.3
index 58c7cc21968..c67e9d9a3f3 100644
--- a/lib/libc/time/strptime.3
+++ b/lib/libc/time/strptime.3
@@ -134,6 +134,9 @@ .Sh DESCRIPTION
 .Dq AM
 or
 .Dq PM .
+.It Cm \&%P
+the same as %p;
+both %P and %p are case-insensitive.
 .It Cm \&%r
 the time as %I:%M:%S %p.
 .It Cm \&%R
diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c
index 2fae1f49220..b3cb1ae8fa6 100644
--- a/lib/libc/time/strptime.c
+++ b/lib/libc/time/strptime.c
@@ -307,6 +307,7 @@ literal:
  fields |= FIELD_TM_MON;
  break;

+ case 'P': /* For symmetry with strftime(). */
  case 'p': /* The locale's equivalent of AM/PM. */
  _LEGAL_ALT(0);
  /* AM? */
diff --git a/lib/libc/time/strptime.3 b/lib/libc/time/strptime.3
index 58c7cc21968..c67e9d9a3f3 100644
--- a/lib/libc/time/strptime.3
+++ b/lib/libc/time/strptime.3
@@ -134,6 +134,9 @@ .Sh DESCRIPTION
 .Dq AM
 or
 .Dq PM .
+.It Cm \&%P
+the same as %p;
+both %P and %p are case-insensitive.
 .It Cm \&%r
 the time as %I:%M:%S %p.
 .It Cm \&%R
diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c
index 2fae1f49220..b3cb1ae8fa6 100644
--- a/lib/libc/time/strptime.c
+++ b/lib/libc/time/strptime.c
@@ -307,6 +307,7 @@ literal:
 			fields |= FIELD_TM_MON;
 			break;
 
+		case 'P':	/* For symmetry with strftime(). */
 		case 'p':	/* The locale's equivalent of AM/PM. */
 			_LEGAL_ALT(0);
 			/* AM? */