]> granicus.if.org Git - php/commitdiff
XSchema stuff finally done right ... (at least i hope so ...)
authorHartmut Holzgraefe <hholzgra@php.net>
Wed, 19 Nov 2003 19:55:13 +0000 (19:55 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Wed, 19 Nov 2003 19:55:13 +0000 (19:55 +0000)
ext/standard/parsedate.y

index 09eea2d9f5d7d9929a201707ef255845be240c45..9b94f12a32f64d057f106eaa0b8f829f97419c9b 100644 (file)
@@ -136,7 +136,6 @@ struct date_yy {
        int     yyRelMonth;
        int     yyRelSeconds;
        int     yyRelYear;
-       int yyFlag;
 };
 
 typedef union _date_ll {
@@ -151,10 +150,12 @@ typedef union _date_ll {
 
 %}
 
-/* This grammar has 19 shift/reduce conflicts. */
-%expect 19
+/* This grammar has 21 shift/reduce conflicts. */
+%expect 21
 %pure_parser
 
+%debug
+
 %token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID tTZONE tZZONE 
 %token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
 %token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
@@ -228,15 +229,25 @@ time      : tUNUMBER tMERIDIAN {
                } else {
                        ((struct date_yy *)parm)->yyTimezone =  -$6 * 60;
                }
-       }
-       | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER pgsqlzonepart {
+    }
+    | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER pgsqlzonepart {
            ((struct date_yy *)parm)->yyHour = $1;
            ((struct date_yy *)parm)->yyMinutes = $3;
            ((struct date_yy *)parm)->yySeconds = $5;
            ((struct date_yy *)parm)->yyMeridian = MER24;
        }
+       | iso8601time
        ;
 
+iso8601time: tUNUMBER ':' tUNUMBER ':' tUNUMBER  {
+           ((struct date_yy *)parm)->yyHour = $1;
+           ((struct date_yy *)parm)->yyMinutes = $3;
+           ((struct date_yy *)parm)->yySeconds = $5;
+           ((struct date_yy *)parm)->yyMeridian = MER24;
+       }  
+    ;
+
+
 pgsqlzonepart : tSNUMBER {
            ((struct date_yy *)parm)->yyHaveZone++;
                if ($1 <= -100 || $1 >= 100) {
@@ -261,14 +272,9 @@ pgsqlzonepart : tSNUMBER {
        */
           
 zone   : tTZONE {
-           ((struct date_yy *)parm)->yyFlag = 1;
            ((struct date_yy *)parm)->yyTimezone = $1;
        }
        | tZZONE {
-               if (((struct date_yy *)parm)->yyFlag) {
-               ((struct date_yy *)parm)->yyHaveZone--;
-                       ((struct date_yy *)parm)->yyFlag = 0;
-               }
            ((struct date_yy *)parm)->yyTimezone = $1;
        }
        | tZONE {
@@ -330,12 +336,17 @@ date      : tUNUMBER '/' tUNUMBER {
              ((struct date_yy *)parm)->yyYear = $5;
            }
        }
-       | tUNUMBER tSNUMBER tSNUMBER {
-           /* ISO 8601 format.  yyyy-mm-dd.  */
-           ((struct date_yy *)parm)->yyYear = $1;
-           ((struct date_yy *)parm)->yyMonth = -$2;
-           ((struct date_yy *)parm)->yyDay = -$3;
-       }
+       | iso8601date
+    | iso8601date tTZONE iso8601time {
+               ((struct date_yy *)parm)->yyTimezone = 0;
+               ((struct date_yy *)parm)->yyHaveZone++;
+                       ((struct date_yy *)parm)->yyHaveTime++;
+    }
+    | iso8601date tTZONE iso8601time tZZONE {
+               ((struct date_yy *)parm)->yyTimezone = 0;
+               ((struct date_yy *)parm)->yyHaveZone++;
+                       ((struct date_yy *)parm)->yyHaveTime++;
+    }
        | tUNUMBER tMONTH tSNUMBER {
            /* e.g. 17-JUN-1992.  */
            ((struct date_yy *)parm)->yyDay = $1;
@@ -375,6 +386,14 @@ date       : tUNUMBER '/' tUNUMBER {
        }
        ;
 
+iso8601date: tUNUMBER tSNUMBER tSNUMBER {
+           /* ISO 8601 format.  yyyy-mm-dd.  */
+           ((struct date_yy *)parm)->yyYear = $1;
+           ((struct date_yy *)parm)->yyMonth = -$2;
+           ((struct date_yy *)parm)->yyDay = -$3;
+       }
+    ;
+
 rel    : relunit tAGO {
            ((struct date_yy *)parm)->yyRelSeconds =
                        -((struct date_yy *)parm)->yyRelSeconds;
@@ -989,13 +1008,12 @@ time_t php_parse_date(char *p, time_t *now)
   date.yyHaveRel = 0;
   date.yyHaveTime = 0;
   date.yyHaveZone = 0;
-  date.yyFlag = 0;
 
   if (yyparse ((void *)&date)
       || date.yyHaveTime > 1 || date.yyHaveZone > 1 
-         || date.yyHaveDate > 1 || date.yyHaveDay > 1)
+         || date.yyHaveDate > 1 || date.yyHaveDay > 1) {
     return -1;
-
+  }
   tm.tm_year = ToYear (date.yyYear) - TM_YEAR_ORIGIN + date.yyRelYear;
   tm.tm_mon = date.yyMonth - 1 + date.yyRelMonth;
   tm.tm_mday = date.yyDay + date.yyRelDay;