/** * If timezone present - xmlnormalize dateTime [E Adding durations to dateTimes] * * @param date CCYY-MM-DDThh:mm:ss+03 * @return CCYY-MM-DDThh:mm:ssZ */ void TimeVal::xmlnormalize() { if ((parser_context.fValue[utc] == UTC_UNKNOWN) || (parser_context.fValue[utc] == UTC_STD) ) return; int negate = (parser_context.fValue[utc] == UTC_POS)? -1: 1; // add mins int temp = parser_context.fValue[Minute] + negate * parser_context.fTimeZone[mm]; int carry = fQuotient(temp, 60); parser_context.fValue[Minute] = mod(temp, 60, carry); //add hours temp = parser_context.fValue[Hour] + negate * parser_context.fTimeZone[hh] + carry; carry = fQuotient(temp, 24); parser_context.fValue[Hour] = mod(temp, 24, carry); parser_context.fValue[Day] += carry; while (1) { temp = maxDayInMonthFor(parser_context.fValue[CentYear], parser_context.fValue[Month]); if (parser_context.fValue[Day] < 1) { parser_context.fValue[Day] += maxDayInMonthFor(parser_context.fValue[CentYear], parser_context.fValue[Month] - 1); carry = -1; } else if ( parser_context.fValue[Day] > temp ) { parser_context.fValue[Day] -= temp; carry = 1; } else { break; } temp = parser_context.fValue[Month] + carry; parser_context.fValue[Month] = modulo(temp, 1, 13); parser_context.fValue[CentYear] += fQuotient(temp, 1, 13); } // set to xmlnormalized parser_context.fValue[utc] = UTC_STD; return; }
static inline int modulo (int temp, int low, int high) { //modulo(a - low, high - low) + low int a = temp - low; int b = high - low; return (mod (a, b, fQuotient(a, b)) + low) ; }
int DateUtils::maximumDayInMonthFor(int year, int month) { int M = modulo(month,1,13); int Y = year + fQuotient(month,1,13); if ( M == 1 || M == 3 || M == 5 || M == 7 || M == 8 || M == 10 || M == 12 ) return 31; else if ( M == 4 || M == 6 || M == 9 || M == 11 ) return 30; else if ( M == 2 && modulo(Y,4) == 0 && ( modulo(Y,400) == 0 || modulo(Y,100) != 0 ) ) return 29; else return 28; }
static inline int fQuotient(int temp, int low, int high) { return fQuotient(temp - low, high - low); }
int DateUtils::fQuotient(int a, int low, int high ) { return fQuotient(a-low,high-low); }
double DateUtils::modulo( double a, double b) { return a - fQuotient(a, b)*b; }
int DateUtils::modulo( int a, int b) { return a - fQuotient(a, b)*b; }