You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/11/02 17:47:14 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs DateTimeDatatypeValidator.java DateTimeValidator.java TimeDatatypeValidator.java

elena       01/11/02 08:47:14

  Modified:    java/src/org/apache/xerces/impl/dv/xs
                        DateTimeDatatypeValidator.java
                        DateTimeValidator.java TimeDatatypeValidator.java
  Log:
  Applied patch from Henry Zongaro (bug fixes 4463 and 4472)
  
  Revision  Changes    Path
  1.2       +3 -3      xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDatatypeValidator.java
  
  Index: DateTimeDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDatatypeValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateTimeDatatypeValidator.java	2001/10/25 20:35:58	1.1
  +++ DateTimeDatatypeValidator.java	2001/11/02 16:47:14	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999, 2001 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -67,7 +67,7 @@
    * Validator for <dateTime> datatype (W3C Schema Datatypes)
    * 
    * @author Elena Litani
  - * @version $Id: DateTimeDatatypeValidator.java,v 1.1 2001/10/25 20:35:58 elena Exp $
  + * @version $Id: DateTimeDatatypeValidator.java,v 1.2 2001/11/02 16:47:14 elena Exp $
    */
   public class DateTimeDatatypeValidator extends DateTimeValidator {
   
  @@ -110,7 +110,7 @@
           validateDateTime(date);
   
   
  -        if ( date[utc]!=0 && date[utc]!='Z') {
  +        if ( (date[utc]!=0 && date[utc]!='Z') || date[h] == 24 ) {
               normalize(date);
           }
           return date;
  
  
  
  1.2       +27 -21    xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeValidator.java
  
  Index: DateTimeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateTimeValidator.java	2001/10/25 20:35:58	1.1
  +++ DateTimeValidator.java	2001/11/02 16:47:14	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999, 2001 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -60,6 +60,7 @@
   import java.util.Vector;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.lang.Math;
   import org.apache.xerces.impl.xpath.regex.RegularExpression;
   import org.apache.xerces.impl.xs.SchemaSymbols;
   import org.apache.xerces.impl.XMLErrorReporter;
  @@ -75,7 +76,7 @@
    * @author Elena Litani
    * @author Len Berman
    *
  - * @version $Id: DateTimeValidator.java,v 1.1 2001/10/25 20:35:58 elena Exp $
  + * @version $Id: DateTimeValidator.java,v 1.2 2001/11/02 16:47:14 elena Exp $
    */
   
   public abstract class DateTimeValidator extends AbstractNumericFacetValidator {
  @@ -561,13 +562,6 @@
           }
           int i = indexOf(start, end, '-');
           if ( i==-1 ) throw new RuntimeException("Year separator is missing or misplaced");
  -        int length = i-start;
  -        if (length<4) {
  -            throw new RuntimeException("Year must have 'CCYY' format");
  -        }
  -        else if (length > 4 && fBuffer.charAt(start)=='0'){
  -            throw new RuntimeException("Leading zeros are required if the year value would otherwise have fewer than four digits; otherwise they are forbidden");
  -        }
           date[CY]= parseIntYear(i);
           if (fBuffer.charAt(i)!='-') {
               throw new RuntimeException("CCYY must be followed by '-' sign");
  @@ -692,28 +686,30 @@
           }
   
           //validate hours
  -        if ( data[h]>23 || data[h]<0 ) {
  -            throw new RuntimeException("Hour must have values 0-23");
  +        if ( data[h]>24 || data[h]<0 ||
  +             (data[h] == 24 && (data[m]!=0 || data[s]!=0 || data[ms]!=0)) ) {
  +            throw new RuntimeException("Hour must have values 0-24.  If hour is 24, minutes and seconds must both have the value 0.");
           }
   
  -        //validate
  +        //validate minutes
           if ( data[m]>59 || data[m]<0 ) {
               throw new RuntimeException("Minute must have values 0-59");
           }
   
  -        //validate
  +        //validate seconds
           if ( data[s]>60 || data[s]<0 ) {
               throw new RuntimeException("Second must have values 0-60");
   
           }
   
  -        //validate
  -        if ( timeZone[hh]>14 || timeZone[hh]<-14 ) {
  +        //validate time-zone hours
  +        if ( Math.abs(timeZone[hh])>14 ||
  +             (Math.abs(timeZone[hh]) == 14 && timeZone[mm] != 0) ) {
               throw new RuntimeException("Time zone should have range -14..+14");
           }
   
  -        //validate
  -        if ( timeZone[mm]>59 || timeZone[mm]<-59 ) {
  +        //validate time-zone minutes
  +        if ( Math.abs(timeZone[mm]) > 59 ) {
               throw new RuntimeException("Minute must have values 0-59");
           }
       }
  @@ -787,6 +783,13 @@
           else{
               limit = -Integer.MAX_VALUE;
           }
  +
  +        int length = end-i;
  +        if (length<4 ||
  +            (length > 4 && fBuffer.charAt(i)=='0')) {
  +            throw new RuntimeException("Leading zeros are required if the year value would otherwise have fewer than four digits; otherwise they are forbidden.");
  +        }
  +
           multmin = limit / radix;
           while (i < end)
           {
  @@ -810,7 +813,9 @@
       }
   
       /**
  -     * If timezone present - normalize dateTime  [E Adding durations to dateTimes]
  +     * Normalize dateTime  [E Adding durations to dateTimes]
  +     *   - If timezone present - normalize to UTC
  +     *   - If hour is 24 - normalize to start of following day
        *
        * @param date   CCYY-MM-DDThh:mm:ss+03
        * @return CCYY-MM-DDThh:mm:ssZ
  @@ -864,8 +869,11 @@
               temp=date[M]+carry;
               date[M]=modulo(temp, 1, 13);
               date[CY]=date[CY]+fQuotient(temp, 1, 13);
  +        }
  +
  +        if (date[utc] != 0) {
  +            date[utc]='Z';
           }
  -        date[utc]='Z';
       }
   
   
  @@ -925,8 +933,6 @@
   
   
       private boolean isLeapYear(int year) {
  -
  -        //REVISIT: should we take care about Julian calendar?
           return((year%4 == 0) && ((year%100 != 0) || (year%400 == 0)));
       }
   
  
  
  
  1.2       +4 -4      xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDatatypeValidator.java
  
  Index: TimeDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDatatypeValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TimeDatatypeValidator.java	2001/10/25 20:35:58	1.1
  +++ TimeDatatypeValidator.java	2001/11/02 16:47:14	1.2
  @@ -3,7 +3,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999, 2000 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999, 2001 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -67,7 +67,7 @@
    * Validator for <time> datatype (W3C Schema Datatypes)
    * 
    * @author Elena Litani
  - * @version $Id: TimeDatatypeValidator.java,v 1.1 2001/10/25 20:35:58 elena Exp $
  + * @version $Id: TimeDatatypeValidator.java,v 1.2 2001/11/02 16:47:14 elena Exp $
    */
   public class TimeDatatypeValidator extends DateTimeValidator {
   
  @@ -113,10 +113,10 @@
           //REVISIT: do we need SchemaDateTimeException?
           validateDateTime(date);
           
  -        if ( date[utc]!=0 ) {
  +        if ( date[utc]!=0 || date[h] == 24 ) {
               normalize(date);
           }
  -                return date;
  +        return date;
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org