sandygao 2004/09/28 14:12:33
Modified: java/src/org/apache/xerces/impl/dv/xs
AbstractDateTimeDV.java DateDV.java DateTimeDV.java
DayDV.java MonthDayDV.java MonthDV.java TimeDV.java
YearDV.java YearMonthDV.java
Log:
Committing a patch from Ankit Pasricha to retain timezone information
after normalization.
Revision Changes Path
1.17 +46 -44
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java
Index: AbstractDateTimeDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- AbstractDateTimeDV.java 20 Sep 2004 22:51:08 -0000 1.16
+++ AbstractDateTimeDV.java 28 Sep 2004 21:12:33 -0000 1.17
@@ -42,8 +42,6 @@
//define shared variables for date/time
- //define constants
- protected final static int hh=0, mm=1;
//define constants to be used in assigning default values for
//all date/time excluding duration
@@ -77,17 +75,16 @@
short c1, c2;
DateTimeData tempDate = new DateTimeData(this);
- int[] timeZone = new int[2];
if ( date1.utc=='Z' ) {
//compare date1<=date1<=(date2 with time zone -14)
//
cloneDate(date2, tempDate); //clones date1 value to global temporary
storage: fTempDate
- timeZone[hh]=14;
- timeZone[mm]=0;
+ tempDate.timezoneHr=14;
+ tempDate.timezoneMin = 0;
tempDate.utc='+';
- normalize(tempDate, timeZone);
+ normalize(tempDate);
c1 = compareOrder(date1, tempDate);
if (c1 == LESS_THAN)
return c1;
@@ -95,10 +92,10 @@
//compare date1>=(date2 with time zone +14)
//
cloneDate(date2, tempDate); //clones date1 value to global temporary
storage: tempDate
- timeZone[hh]=14;
- timeZone[mm]=0;
+ tempDate.timezoneHr = -14;
+ tempDate.timezoneMin = 0;
tempDate.utc='-';
- normalize(tempDate, timeZone);
+ normalize(tempDate);
c2 = compareOrder(date1, tempDate);
if (c2 == GREATER_THAN)
return c2;
@@ -110,13 +107,13 @@
//compare (date1 with time zone -14)<=date2
//
cloneDate(date1, tempDate); //clones date1 value to global temporary
storage: tempDate
- timeZone[hh]=14;
- timeZone[mm]=0;
+ tempDate.timezoneHr = -14;
+ tempDate.timezoneMin = 0;
tempDate.utc='-';
if (DEBUG) {
System.out.println("tempDate=" + dateToString(tempDate));
}
- normalize(tempDate, timeZone);
+ normalize(tempDate);
c1 = compareOrder(tempDate, date2);
if (DEBUG) {
System.out.println("date=" + dateToString(date2));
@@ -128,10 +125,10 @@
//compare (date1 with time zone +14)<=date2
//
cloneDate(date1, tempDate); //clones date1 value to global temporary
storage: tempDate
- timeZone[hh]=14;
- timeZone[mm]=0;
+ tempDate.timezoneHr = 14;
+ tempDate.timezoneMin = 0;
tempDate.utc='+';
- normalize(tempDate, timeZone);
+ normalize(tempDate);
c2 = compareOrder(tempDate, date2);
if (DEBUG) {
System.out.println("tempDate=" + dateToString(tempDate));
@@ -193,7 +190,7 @@
* @param data
* @exception RuntimeException
*/
- protected void getTime (String buffer, int start, int end, DateTimeData data,
int[] timeZone) throws RuntimeException{
+ protected void getTime (String buffer, int start, int end, DateTimeData data)
throws RuntimeException{
int stop = start+2;
@@ -224,7 +221,7 @@
//parse UTC time zone (hh:mm)
if (sign > 0) {
- getTimeZone(buffer, data, sign, end, timeZone);
+ getTimeZone(buffer, data, sign, end);
}
}
@@ -291,7 +288,7 @@
* @param date
* @exception RuntimeException
*/
- protected void parseTimeZone (String buffer, int start, int end, DateTimeData
date, int[] timeZone) throws RuntimeException{
+ protected void parseTimeZone (String buffer, int start, int end, DateTimeData
date) throws RuntimeException{
//fStart points right after the date
@@ -301,7 +298,7 @@
throw new RuntimeException ("Error in month parsing");
}
else {
- getTimeZone(buffer, date, sign, end, timeZone);
+ getTimeZone(buffer, date, sign, end);
}
}
}
@@ -313,7 +310,7 @@
* @param sign
* @exception RuntimeException
*/
- protected void getTimeZone (String buffer, DateTimeData data, int sign, int
end, int[] timeZone) throws RuntimeException{
+ protected void getTimeZone (String buffer, DateTimeData data, int sign, int
end) throws RuntimeException{
data.utc=buffer.charAt(sign);
if ( buffer.charAt(sign) == 'Z' ) {
@@ -324,26 +321,26 @@
}
if ( sign<=(end-6) ) {
- //parse [hh]
+ int negate = buffer.charAt(sign) == '-'?-1:1;
+ //parse hr
int stop = ++sign+2;
- timeZone[hh]=parseInt(buffer, sign, stop);
+ data.timezoneHr = negate*parseInt(buffer, sign, stop);
if (buffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
- //parse [ss]
- timeZone[mm]=parseInt(buffer, stop, stop+2);
+ //parse min
+ data.timezoneMin = negate*parseInt(buffer, stop, stop+2);
if ( stop+2!=end ) {
throw new RuntimeException("Error in parsing time zone");
}
-
}
else {
throw new RuntimeException("Error in parsing time zone");
}
if ( DEBUG ) {
- System.out.println("time[hh]="+timeZone[hh] + " time[mm]="
+timeZone[mm]);
+ System.out.println("time[hh]="+data.timezoneHr + " time[mm]="
+data.timezoneMin);
}
}
@@ -370,7 +367,7 @@
*
* @param data
*/
- protected void validateDateTime (DateTimeData data, int[] timeZone) {
+ protected void validateDateTime (DateTimeData data) {
//REVISIT: should we throw an exception for not valid dates
// or reporting an error message should be sufficient?
@@ -406,10 +403,10 @@
}
else if (++data.year == 0) {
data.year = 1;
- }
}
}
}
+ }
else {
throw new RuntimeException("Hour must have values 0-23, unless
24:00:00");
}
@@ -427,14 +424,16 @@
}
//validate
- if ( timeZone[hh]>14 || timeZone[hh]<-14 ) {
- throw new RuntimeException("Time zone should have range -14..+14");
+ if ( data.timezoneHr>14 || data.timezoneHr<-14 ) {
+ throw new RuntimeException("Time zone should have range -14:00 to
+14:00");
}
-
- //validate
- if ( timeZone[mm]>59 || timeZone[mm]<-59 ) {
- throw new RuntimeException("Minute must have values 0-59");
+ else {
+ if((data.timezoneHr == 14 || data.timezoneHr == -14) &&
data.timezoneMin != 0)
+ throw new RuntimeException("Time zone should have range -14:00
to +14:00");
+ else if(data.timezoneMin > 59 || data.timezoneMin < -59)
+ throw new RuntimeException("Minute must have values 0-59");
}
+
}
/**
@@ -530,22 +529,20 @@
* @param date CCYY-MM-DDThh:mm:ss+03
* @return CCYY-MM-DDThh:mm:ssZ
*/
- protected void normalize(DateTimeData date, int[] timeZone) {
+ protected void normalize(DateTimeData date) {
// REVISIT: we have common code in addDuration() for durations
// should consider reorganizing it.
//
-
+
//add minutes (from time zone)
- int negate = 1;
- if (date.utc=='+') {
- negate = -1;
- }
+ int negate = -1;
+
if ( DEBUG ) {
System.out.println("==>date.minute"+date.minute);
- System.out.println("==>timeZone[mm]" +timeZone[mm]);
+ System.out.println("==>date.timezoneMin" +date.timezoneMin);
}
- int temp = date.minute + negate*timeZone[mm];
+ int temp = date.minute + negate * date.timezoneMin;
int carry = fQuotient (temp, 60);
date.minute= mod(temp, 60, carry);
@@ -553,7 +550,7 @@
System.out.println("==>carry: " + carry);
}
//add hours
- temp = date.hour + negate*timeZone[hh] + carry;
+ temp = date.hour + negate * date.timezoneHr + carry;
carry = fQuotient(temp, 24);
date.hour=mod(temp, 24, carry);
if ( DEBUG ) {
@@ -597,6 +594,8 @@
data.minute = 0;
data.second = 0;
data.utc = 0;
+ data.timezoneHr = 0;
+ data.timezoneMin = 0;
}
/**
@@ -752,6 +751,8 @@
tempDate.minute = finalValue.minute;
tempDate.second = finalValue.second;
tempDate.utc = finalValue.utc;
+ tempDate.timezoneHr = finalValue.timezoneHr;
+ tempDate.timezoneMin = finalValue.timezoneMin;
}
/**
@@ -760,6 +761,7 @@
static final class DateTimeData {
int year, month, day, hour, minute, utc;
double second;
+ int timezoneHr, timezoneMin;
// a pointer to the type that was used go generate this data
// note that this is not the actual simple type, but one of the
// statically created XXXDV objects, so this won't cause any GC problem.
1.12 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java
Index: DateDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DateDV.java 26 Aug 2004 02:14:40 -0000 1.11
+++ DateDV.java 28 Sep 2004 21:12:33 -0000 1.12
@@ -48,17 +48,16 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
int end = getDate(str, 0, len, date);
- parseTimeZone (str, end, len, date, timeZone);
+ parseTimeZone (str, end, len, date);
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if (date.utc!=0 && date.utc!='Z') {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java
Index: DateTimeDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DateTimeDV.java 26 Aug 2004 02:14:40 -0000 1.9
+++ DateTimeDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -49,13 +49,12 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException {
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
int end = indexOf (str, 0, len, 'T');
// both time and date
int dateEnd = getDate(str, 0, end, date);
- getTime(str, end+1, len, date, timeZone);
+ getTime(str, end+1, len, date);
//Check the separator character between Date and Time
if (dateEnd != end) {
@@ -67,10 +66,10 @@
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if (date.utc!=0 && date.utc!='Z') {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java
Index: DayDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DayDV.java 26 Aug 2004 02:14:40 -0000 1.9
+++ DayDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -52,7 +52,6 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException {
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
if (str.charAt(0)!='-' || str.charAt(1)!='-' || str.charAt(2)!='-') {
throw new SchemaDateTimeException ("Error in day parsing");
@@ -70,15 +69,15 @@
throw new SchemaDateTimeException ("Error in day parsing");
}
else {
- getTimeZone(str, date, sign, len, timeZone);
+ getTimeZone(str, date, sign, len);
}
}
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 && date.utc!='Z' ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java
Index: MonthDayDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MonthDayDV.java 26 Aug 2004 02:14:40 -0000 1.9
+++ MonthDayDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -59,7 +59,6 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
//initialize
date.year=YEAR;
@@ -82,15 +81,15 @@
throw new SchemaDateTimeException ("Error in month parsing:" +str);
}
else {
- getTimeZone(str, date, sign, len, timeZone);
+ getTimeZone(str, date, sign, len);
}
}
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 && date.utc!='Z' ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.12 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java
Index: MonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MonthDV.java 26 Aug 2004 02:14:40 -0000 1.11
+++ MonthDV.java 28 Sep 2004 21:12:33 -0000 1.12
@@ -56,7 +56,6 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
//set constants
date.year=YEAR;
@@ -80,14 +79,14 @@
throw new SchemaDateTimeException ("Error in month parsing: "+str);
}
else {
- getTimeZone(str, date, sign, len, timeZone);
+ getTimeZone(str, date, sign, len);
}
}
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 && date.utc!='Z' ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java
Index: TimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TimeDV.java 26 Aug 2004 02:14:40 -0000 1.9
+++ TimeDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -56,21 +56,20 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
// time
// initialize to default values
date.year=YEAR;
date.month=MONTH;
date.day=DAY;
- getTime(str, 0, len, date, timeZone);
+ getTime(str, 0, len, date);
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java
Index: YearDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- YearDV.java 26 Aug 2004 02:14:41 -0000 1.9
+++ YearDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -56,7 +56,6 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
// check for preceding '-' sign
int start = 0;
@@ -69,7 +68,7 @@
}
else {
date.year=parseIntYear(str, sign);
- getTimeZone (str, date, sign, len, timeZone);
+ getTimeZone (str, date, sign, len);
}
//initialize values
@@ -77,10 +76,10 @@
date.day=1;
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 && date.utc!='Z' ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
1.10 +4 -5
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java
Index: YearMonthDV.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- YearMonthDV.java 26 Aug 2004 02:14:41 -0000 1.9
+++ YearMonthDV.java 28 Sep 2004 21:12:33 -0000 1.10
@@ -55,19 +55,18 @@
protected DateTimeData parse(String str) throws SchemaDateTimeException{
DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] timeZone = new int[2];
// get date
int end = getYearMonth(str, 0, len, date);
date.day = DAY;
- parseTimeZone (str, end, len, date, timeZone);
+ parseTimeZone (str, end, len, date);
//validate and normalize
- validateDateTime(date, timeZone);
+ validateDateTime(date);
if ( date.utc!=0 && date.utc!='Z' ) {
- normalize(date, timeZone);
+ normalize(date);
}
return date;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]