This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch for strptime.


Hi,

This patch make the `%C' format specifier actually useful.

Mark


1998-12-03  Mark Kettenis  <kettenis@phys.uva.nl>

	* time/strptime.c (strptime_internal): Make use of `%C' format
	specifier if it is seen together with the `%y' specifier.


--- /home/kettenis/CVS/libc/time/strptime.c	Sun Nov  1 21:28:31 1998
+++ libc/time/strptime.c	Sat Nov 28 16:27:33 1998
@@ -203,10 +203,13 @@
   int cnt;
   size_t val;
   int have_I, is_pm;
+  int century, want_century;
 
   rp = buf;
   fmt = format;
   have_I = is_pm = 0;
+  century = -1;
+  want_century = 0;
 
   while (*fmt != '\0')
     {
@@ -343,7 +346,7 @@
 	case 'C':
 	  /* Match century number.  */
 	  get_number (0, 99);
-	  /* We don't need the number.  */
+	  century = val;
 	  break;
 	case 'd':
 	case 'e':
@@ -548,11 +551,14 @@
 	  /* The "Year 2000 :The Millennium Rollover" paper suggests that
 	     values in the range 69-99 refer to the twentieth century.  */
 	  tm->tm_year = val >= 69 ? val : val + 100;
+	  /* Indicate that we want to use the century, if specified
+	  want_century = 1;
 	  break;
 	case 'Y':
 	  /* Match year including century number.  */
 	  get_number (0, 9999);
 	  tm->tm_year = val - 1900;
+	  want_century = 0;
 	  break;
 	case 'Z':
 	  /* XXX How to handle this?  */
@@ -724,6 +730,9 @@
 
   if (have_I && is_pm)
     tm->tm_hour += 12;
+
+  if (want_century && century != -1)
+    tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
 
   return (char *) rp;
 }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]