/** * Comparison function. Not quite the same as normal java compare * because XSD date/times are not always comparable. * * @param other the time/date to compare to * @return an order flag - one of LESS_THAN, EQUAL, GREATER_THEN, INDETERMINATE */ public int compare(AbstractDateTime other) { return compareDates(data, other.data, true); }
/** * Constructor * @param value the date/time value returned by the parsing */ public AbstractDateTime(Object value) { data = (int[]) value; //if (data[utc] == 0) data[utc]='Z'; extractFractionalSeconds(); }
int carry = fQuotient (temp, 60); date[m]= mod(temp, 60, carry); carry = fQuotient(temp, 24); date[h]=mod(temp, 24, carry); temp=maxDayInMonthFor(date[CY], date[M]); if (date[D]<1) { date[D] = date[D] + maxDayInMonthFor(date[CY], date[M]-1); carry=-1; date[M]=modulo(temp, 1, 13); date[CY]=date[CY]+fQuotient(temp, 1, 13);
return compareOrder(date1, date2); cloneDate(date2, tempDate); //clones date1 value to global temporary storage: fTempDate timeZone[hh]=14; timeZone[mm]=0; tempDate[utc]='+'; normalize(tempDate, timeZone); c1 = compareOrder(date1, tempDate); if (c1 == LESS_THAN) return c1; cloneDate(date2, tempDate); //clones date1 value to global temporary storage: tempDate timeZone[hh]=14; timeZone[mm]=0; tempDate[utc]='-'; normalize(tempDate, timeZone); c2 = compareOrder(date1, tempDate); if (c2 == GREATER_THAN) return c2; cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate timeZone[hh]=14; timeZone[mm]=0; tempDate[utc]='-'; normalize(tempDate, timeZone); c1 = compareOrder(tempDate, date2); if (c1 == LESS_THAN) return c1;
protected static int fQuotient (int temp, int low, int high) { //fQuotient(a - low, high - low) return fQuotient(temp - low, high - low); }
/** * Normal java comparison function. Treats INDETERMINATE as the same * as equals. This is not strictly correct but seems like an appropriate * way to handle partially ordered objects. */ @Override public int compareTo(AbstractDateTime o) { switch (compare(o)) { case EQUAL: case INDETERMINATE: return 0; case LESS_THAN: return -1; case GREATER_THAN: return 1; } return 0; }
/** * Given {year,month} computes maximum * number of days for given month * * @param year * @param month * @return integer containg the number of days in a given month */ protected static int maxDayInMonthFor(int year, int month) { //validate days if ( month==4 || month==6 || month==9 || month==11 ) { return 30; } else if ( month==2 ) { if ( isLeapYear(year) ) { return 29; } else { return 28; } } else { return 31; } }