glibc: standard date/time format patch

Eduardo Pérez Ureta eperez@it.uc3m.es
Fri Aug 16 09:07:00 GMT 2002


Hi,

There's a confusion what the standard date/time format is, in glibc.

The standard date/time format is ISO 8601:
http://www.cl.cam.ac.uk/~mgk25/iso-time.html

This patch fixes glibc to use ISO 8601 as standard date/time format in
the C locale, as the American date/time format is not the standard one.

The American date/time format can still be used in the American locale.

This fix will help people read dates in the C locale with the advantages
of this date/time format.

                Eduardo
-------------- next part --------------
--- glibc-2.2.5-old/locale/C-time.c
+++ glibc-2.2.5/locale/C-time.c
@@ -73,7 +73,7 @@
     { string: "AM" },
     { string: "PM" },
     { string: "%a %b %e %H:%M:%S %Y" },
-    { string: "%m/%d/%y" },
+    { string: "%Y-%m-%d" },
     { string: "%H:%M:%S" },
     { string: "%I:%M:%S %p" },
     { string: NULL },
@@ -125,7 +125,7 @@
     { wstr: (const uint32_t *) L"AM" },
     { wstr: (const uint32_t *) L"PM" },
     { wstr: (const uint32_t *) L"%a %b %e %H:%M:%S %Y" },
-    { wstr: (const uint32_t *) L"%m/%d/%y" },
+    { wstr: (const uint32_t *) L"%Y-%m-%d" },
     { wstr: (const uint32_t *) L"%H:%M:%S" },
     { wstr: (const uint32_t *) L"%I:%M:%S %p" },
     { wstr: (const uint32_t *) L"" },
--- glibc-2.2.5-old/locale/tst-C-locale.c
+++ glibc-2.2.5/locale/tst-C-locale.c
@@ -151,7 +151,7 @@
   STRTEST (AM_STR, "AM");
   STRTEST (PM_STR, "PM");
   STRTEST (D_T_FMT, "%a %b %e %H:%M:%S %Y");
-  STRTEST (D_FMT, "%m/%d/%y");
+  STRTEST (D_FMT, "%Y-%m-%d");
   STRTEST (T_FMT, "%H:%M:%S");
   STRTEST (T_FMT_AMPM, "%I:%M:%S %p");
 
@@ -203,7 +203,7 @@
   WSTRTEST (_NL_WAM_STR, L"AM");
   WSTRTEST (_NL_WPM_STR, L"PM");
   WSTRTEST (_NL_WD_T_FMT, L"%a %b %e %H:%M:%S %Y");
-  WSTRTEST (_NL_WD_FMT, L"%m/%d/%y");
+  WSTRTEST (_NL_WD_FMT, L"%Y-%m-%d");
   WSTRTEST (_NL_WT_FMT, L"%H:%M:%S");
   WSTRTEST (_NL_WT_FMT_AMPM, L"%I:%M:%S %p");
 
@@ -294,7 +294,7 @@
       STRTEST (AM_STR, "AM");
       STRTEST (PM_STR, "PM");
       STRTEST (D_T_FMT, "%a %b %e %H:%M:%S %Y");
-      STRTEST (D_FMT, "%m/%d/%y");
+      STRTEST (D_FMT, "%Y-%m-%d");
       STRTEST (T_FMT, "%H:%M:%S");
       STRTEST (T_FMT_AMPM, "%I:%M:%S %p");
 
@@ -346,7 +346,7 @@
       WSTRTEST (_NL_WAM_STR, L"AM");
       WSTRTEST (_NL_WPM_STR, L"PM");
       WSTRTEST (_NL_WD_T_FMT, L"%a %b %e %H:%M:%S %Y");
-      WSTRTEST (_NL_WD_FMT, L"%m/%d/%y");
+      WSTRTEST (_NL_WD_FMT, L"%Y-%m-%d");
       WSTRTEST (_NL_WT_FMT, L"%H:%M:%S");
       WSTRTEST (_NL_WT_FMT_AMPM, L"%I:%M:%S %p");
 
--- glibc-2.2.5-old/localedata/tst-langinfo.sh
+++ glibc-2.2.5/localedata/tst-langinfo.sh
@@ -66,7 +66,7 @@
 C                    AM_STR      AM
 C                    PM_STR      PM
 C                    D_T_FMT     "%a %b %e %H:%M:%S %Y"
-C                    D_FMT       "%m/%d/%y"
+C                    D_FMT       "%Y-%m-%d"
 C                    T_FMT       "%H:%M:%S"
 C                    T_FMT_AMPM  "%I:%M:%S %p"
 C                    ABDAY_1     Sun
--- glibc-2.2.5-old/locale/programs/ld-time.c
+++ glibc-2.2.5/locale/programs/ld-time.c
@@ -198,7 +198,7 @@
     }
 
   TEST_ELEM (d_t_fmt, "%a %b %e %H:%M:%S %Y");
-  TEST_ELEM (d_fmt, "%m/%d/%y");
+  TEST_ELEM (d_fmt, "%Y-%m-%d");
   TEST_ELEM (t_fmt, "%H:%M:%S");
 
   /* According to C.Y.Alexis Cheng <alexis@vnet.ibm.com> the T_FMT_AMPM
--- glibc-2.2.5-old/localedata/locales/POSIX
+++ glibc-2.2.5/localedata/locales/POSIX
@@ -307,8 +307,8 @@
 <U0020><U0025><U0048><U003A><U0025><U004D>\
 <U003A><U0025><U0053><U0020><U0025><U0059>"
 #
-# Appropriate date representation (%x)   "%m/%d/%y"
-d_fmt   "<U0025><U006D><U002F><U0025><U0064><U002F><U0025><U0079>"
+# Appropriate date representation (%x)   "%Y-%m-%d"
+d_fmt   "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064>"
 #
 # Appropriate time representation (%X)   "%H:%M:%S"
 t_fmt   "<U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
--- glibc-2.2.5-old/time/strptime.c
+++ glibc-2.2.5/time/strptime.c
@@ -171,7 +171,7 @@
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
   };
 # define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y"
-# define HERE_D_FMT "%m/%d/%y"
+# define HERE_D_FMT "%Y-%m-%d"
 # define HERE_AM_STR "AM"
 # define HERE_PM_STR "PM"
 # define HERE_T_FMT_AMPM "%I:%M:%S %p"
@@ -422,8 +422,9 @@
 	  have_mday = 1;
 	  want_xday = 1;
 	  break;
-	case 'F':
-	  if (!recursive ("%Y-%m-%d"))
+	case 'D':
+	  /* Match American style date format.  */
+	  if (!recursive ("%m/%d/%y"))
 	    return NULL;
 	  want_xday = 1;
 	  break;
@@ -450,9 +451,9 @@
 	    }
 #endif
 	  /* Fall through.  */
-	case 'D':
+	case 'F':
 	  /* Match standard day format.  */
-	  if (!recursive (HERE_D_FMT))
+	  if (!recursive ("%Y-%m-%d"))
 	    return NULL;
 	  want_xday = 1;
 	  break;


More information about the Libc-alpha mailing list