about summary refs log tree commit diff
path: root/time/strptime_l.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-04-27 04:33:01 +0000
committerUlrich Drepper <drepper@redhat.com>2005-04-27 04:33:01 +0000
commit935f3e6715f2f178159eef1501ae30ad53a68150 (patch)
treef484c7c6c87c97774f3840c051804e42aa3588c0 /time/strptime_l.c
parentbfc832ccf15e467b6271e8b237e467a30efd3d12 (diff)
downloadglibc-935f3e6715f2f178159eef1501ae30ad53a68150.tar.gz
glibc-935f3e6715f2f178159eef1501ae30ad53a68150.tar.xz
glibc-935f3e6715f2f178159eef1501ae30ad53a68150.zip
* time/strptime_l.c (__strptime_internal): Handle 'z' to set
	tm_gmtoff.
	* time/Makefile (tests): Add tst-strptime2.
	* time/tst-strptime2.c: New file.
Diffstat (limited to 'time/strptime_l.c')
-rw-r--r--time/strptime_l.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/time/strptime_l.c b/time/strptime_l.c
index 01c4f8282a..dc0cc686fd 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -687,6 +687,42 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 	case 'Z':
 	  /* XXX How to handle this?  */
 	  break;
+	case 'z':
+	  /* We recognize two formats: if two digits are given, these
+	     specify hours.  If fours digits are used, minutes are
+	     also specified.  */
+	  {
+	    val = 0;
+	    while (*rp == ' ')
+	      ++rp;
+	    if (*rp != '+' && *rp != '-')
+	      return NULL;
+	    bool neg = *rp++ == '-';
+	    int n = 0;
+	    while (n < 4 && *rp >= '0' && *rp <= '9')
+	      {
+		val = val * 10 + *rp++ - '0';
+		++n;
+	      }
+	    if (n == 2)
+	      val *= 100;
+	    else if (n != 4)
+	      /* Only two or four digits recognized.  */
+	      return NULL;
+	    else
+	      {
+		/* We have to convert the minutes into decimal.  */
+		if (val % 100 >= 60)
+		  return NULL;
+		val = (val / 100) * 100 + ((val % 100) * 50) / 30;
+	      }
+	    if (val > 1200)
+	      return NULL;
+	    tm->tm_gmtoff = (val * 3600) / 100;
+	    if (neg)
+	      tm->tm_gmtoff = -tm->tm_gmtoff;
+	  }
+	  break;
 	case 'E':
 #ifdef _NL_CURRENT
 	  switch (*fmt++)