Author: cargilld
Date: Thu Jul 28 11:57:40 2005
New Revision: 225849

URL: http://svn.apache.org/viewcvs?rev=225849&view=rev
Log:
Fix duration date time problems.

Modified:
    xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp

Modified: xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp
URL: 
http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp?rev=225849&r1=225848&r2=225849&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLDateTime.cpp Thu Jul 28 11:57:40 2005
@@ -229,7 +229,7 @@
     int temp = DATETIMES[index][Month] + fDuration->fValue[Month];
     fNewDate->fValue[Month] = modulo(temp, 1, 13);
     int carry = fQuotient(temp, 1, 13);
-    if (fNewDate->fValue[Month] < 0) {
+    if (fNewDate->fValue[Month] <= 0) {
         fNewDate->fValue[Month]+= 12;
         carry--;
     }
@@ -286,12 +286,11 @@
 
         temp = fNewDate->fValue[Month] + carry;
         fNewDate->fValue[Month] = modulo(temp, 1, 13);
-        if (fNewDate->fValue[Month] < 0) {
+        if (fNewDate->fValue[Month] <= 0) {
             fNewDate->fValue[Month]+= 12;
-            carry--;
+            fNewDate->fValue[CentYear]--;
         }
-        else
-            fNewDate->fValue[CentYear] += fQuotient(temp, 1, 13);
+        fNewDate->fValue[CentYear] += fQuotient(temp, 1, 13);
     }
 
     //fNewDate->fValue[utc] = UTC_STD_CHAR;
@@ -1199,13 +1198,27 @@
     int negate = (fValue[utc] == UTC_POS)? -1: 1;
     int temp;
     int carry;
+    
+
+    // we normalize a duration so could have 200M...
+    //update months (may be modified additionaly below)
+    temp = fValue[Month];
+    fValue[Month] = modulo(temp, 1, 13);
+    carry = fQuotient(temp, 1, 13);
+    if (fValue[Month] <= 0) {
+        fValue[Month]+= 12;
+        carry--;
+    }
+
+    //add years (may be modified additionaly below)
+    fValue[CentYear] += carry;
 
     // add mins
     temp = fValue[Minute] + negate * fTimeZone[mm];
     carry = fQuotient(temp, 60);
     fValue[Minute] = mod(temp, 60, carry);
-    if (temp < 0) {
-        fValue[Minute] = temp + 60;
+    if (fValue[Minute] < 0) {
+        fValue[Minute] += 60;
         carry--;
     }
    
@@ -1213,12 +1226,12 @@
     temp = fValue[Hour] + negate * fTimeZone[hh] + carry;
     carry = fQuotient(temp, 24);
     fValue[Hour] = mod(temp, 24, carry);
-    if (temp < 0) {
-        fValue[Hour] = temp + 24;
+    if (fValue[Hour] < 0) {
+        fValue[Hour] += 24;
         carry--;
     }
 
-    fValue[Day] += carry;
+    fValue[Day] += carry;   
 
     while (1)
     {
@@ -1654,8 +1667,7 @@
                 month+= 12;
                 year--;
             }
-            else
-                year += fQuotient(temp, 1, 13);         
+            year += fQuotient(temp, 1, 13);         
         }
 
         int additionalLen = fillYearString(retPtr, year);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to