Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
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) ;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
static inline int fQuotient(int temp, int low, int high)
{
  return fQuotient(temp - low, high - low);
}
Ejemplo n.º 5
0
int DateUtils::fQuotient(int a, int low, int high ) {
    return fQuotient(a-low,high-low);
}
Ejemplo n.º 6
0
double DateUtils::modulo( double a, double b) {
   return a - fQuotient(a, b)*b;
}
Ejemplo n.º 7
0
int DateUtils::modulo( int a, int b)  {
   return a - fQuotient(a, b)*b;
}