/** * Returns true if the present instance of date/time type is equal to the parameter. * <p> * The equals relation is as defined in the W3C XML Schema Recommendation, part2. * * @param dateTime the date/time type to compare with the present instance * @return true if the present instance is equal to the parameter false if not */ protected boolean equal(DateTimeBase dateTime) { return EQUALS == this.compareTo(dateTime); } // equals
/** * {@inheritDoc} * Overrides the java.lang.Object#equals method. * @see #equals(Object) */ public boolean equals(Object object) { // No need to check if we are comparing two instances of the same class. // (if the class is not the same then #equal will return false). if (object instanceof DateTimeBase) { return equal((DateTimeBase) object); } return false; }
/** * Helper function defined in W3C XML Schema Recommendation part 2. * * @see <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> W3C XML Schema * Recommendation part 2</a> */ private int modulo(int a, int b) { return a - fQuotient(a, b) * b; }
if (date1.hasCentury() != date2.hasCentury()) { return INDETERMINATE; if (date1.hasCentury() && date2.hasCentury()) { field1 = date1.getCentury(); field2 = date2.getCentury(); if (field1 < field2) { return LESS_THAN; if (date1.hasYear() != date2.hasYear()) { return INDETERMINATE; if (date1.hasYear() && date2.hasYear()) { field1 = date1.getYear(); field2 = date2.getYear(); if (field1 < field2) { return LESS_THAN; if (date1.hasMonth() != date2.hasMonth()) { return INDETERMINATE; if (date1.hasMonth() && date2.hasMonth()) { field1 = date1.getMonth(); field2 = date2.getMonth(); if (field1 < field2) { return LESS_THAN; if (date1.hasDay() != date2.hasDay()) { return INDETERMINATE;
carry = fQuotient(temp - 1, 12); this.setMonth((short) (modulo(temp - 1, 12) + 1)); } catch (UnsupportedOperationException e) { this.setCentury((short) (temp / 100)); this.setYear((short) (temp % 100)); } catch (UnsupportedOperationException e) { tempDay = 1; } else { int maxDay = maxDayInMonthFor(_century, _year, _month); if (_day > maxDay) { tempDay = maxDay; carry = fQuotient(temp, 1000); this.setMilliSecond((short) modulo(temp, 1000)); carry = fQuotient(temp, 60); this.setSecond((short) modulo(temp, 60)); } catch (UnsupportedOperationException e) { carry = fQuotient(temp, 60); this.setMinute((short) modulo(temp, 60)); } catch (UnsupportedOperationException e) { carry = fQuotient(temp, 24); this.setHour((short) modulo(temp, 24)); } catch (UnsupportedOperationException e) {
tempDate1 = clone(this); if (tempDate1.isUTC()) { tempDate1.normalize(); tempDate2 = clone(dateTime); if (tempDate2.isUTC()) { tempDate2.normalize(); if (tempDate1.isUTC() == tempDate2.isUTC()) { return compareFields(tempDate1, tempDate2); if (tempDate1.isUTC()) { tempDate2.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate2.normalize(); int result = compareFields(tempDate1, tempDate2); if (result == LESS_THAN) { return result; tempDate2.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate2.setZoneNegative(true); tempDate2.normalize(); tempDate2.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate2.setZoneNegative(true); tempDate2.normalize(); result = compareFields(tempDate1, tempDate2); if (result == GREATER_THAN) { return result;
protected void appendDateString(StringBuffer result) { if (isNegative()) { result.append('-'); } if ((this.getCentury() / 10) == 0) { result.append(0); } result.append(this.getCentury()); if ((this.getYear() / 10) == 0) { result.append(0); } result.append(this.getYear()); result.append('-'); if ((this.getMonth() / 10) == 0) { result.append(0); } result.append(this.getMonth()); result.append('-'); if ((this.getDay() / 10) == 0) { result.append(0); } result.append(this.getDay()); }
/** * Normalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a * timeZone is present but it is not Z then we convert the date/time datatype to Z using the * addition operation defined in * <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> Adding Duration to * dateTimes (W3C XML Schema, part 2 appendix E).</a> * * @see #addDuration */ public void normalize() { if (!isUTC() || (_zoneHour == 0 && _zoneMinute == 0)) { return; } Duration temp = new Duration(); temp.setHour(_zoneHour); temp.setMinute(_zoneMinute); if (!isZoneNegative()) { temp.setNegative(); } this.addDuration(temp); // reset the zone this.setZone((short) 0, (short) 0); this.setZoneNegative(false); }
result.setHour((short) 0); Duration oneDay = new Duration(); oneDay.setDay((short) 1); result.addDuration(oneDay); isHourOfValue24 = true; } else { result.setHour(hour); idx); result.setMinute(minutes); idx); result.setSecond(seconds); powerOfTen = 1000; result.setMilliSecond((short) decimalValue);
protected void appendTimeString(StringBuffer result) { if ((this.getHour() / 10) == 0) { result.append(0); } result.append(this.getHour()); result.append(':'); if ((this.getMinute() / 10) == 0) { result.append(0); } result.append(this.getMinute()); result.append(':'); if ((this.getSeconds() / 10) == 0) { result.append(0); } result.append(this.getSeconds()); if (this.getMilli() != 0) { result.append('.'); if (this.getMilli() < 100) { result.append('0'); if (this.getMilli() < 10) { result.append('0'); } } result.append(this.getMilli()); } }
int comparison = dateTime.compareTo(_fixed); if (comparison == DateTimeBase.INDETERMINATE) { String err = dateTime.getClass().getName() + " " + dateTime if (isThereMinInclusive && dateTime.compareTo(_minInclusive) != DateTimeBase.GREATER_THAN && !dateTime.equals(_minInclusive)) { String err = dateTime.getClass().getName() + " " + dateTime + " is less than the minimum allowed value: " + _minInclusive; if (isThereMinExclusive && dateTime.compareTo(_minExclusive) != DateTimeBase.GREATER_THAN) { String err = dateTime.getClass().getName() + " " + dateTime + " is less than or equal to the minimum (exclusive) value: " + _minExclusive; if (isThereMaxInclusive && dateTime.compareTo(_maxInclusive) != DateTimeBase.LESS_THAN && !dateTime.equals(_maxInclusive)) { String err = dateTime.getClass().getName() + " " + dateTime + " is greater than the maximum allowed value: " + _maxInclusive; if (isThereMaxExclusive && dateTime.compareTo(_maxExclusive) != DateTimeBase.LESS_THAN) { String err = dateTime.getClass().getName() + " " + dateTime + " is greater than or equal to the maximum (exclusive) value: " + _maxExclusive;
if (date1.hasCentury() != date2.hasCentury()) { return INDETERMINATE; if (date1.hasCentury() && date2.hasCentury()) { field1 = date1.getCentury(); field2 = date2.getCentury(); if (field1 < field2) { return LESS_THAN; if (date1.hasYear() != date2.hasYear()) { return INDETERMINATE; if (date1.hasYear() && date2.hasYear()) { field1 = date1.getYear(); field2 = date2.getYear(); if (field1 < field2) { return LESS_THAN; if (date1.hasMonth() != date2.hasMonth()) { return INDETERMINATE; if (date1.hasMonth() && date2.hasMonth()) { field1 = date1.getMonth(); field2 = date2.getMonth(); if (field1 < field2) { return LESS_THAN; if (date1.hasDay() != date2.hasDay()) { return INDETERMINATE;
carry = fQuotient(temp - 1, 12); this.setMonth((short) (modulo(temp - 1, 12) + 1)); } catch (UnsupportedOperationException e) { this.setCentury((short) (temp / 100)); this.setYear((short) (temp % 100)); } catch (UnsupportedOperationException e) { tempDay = 1; } else { int maxDay = maxDayInMonthFor(_century, _year, _month); if (_day > maxDay) { tempDay = maxDay; carry = fQuotient(temp, 1000); this.setMilliSecond((short)modulo(temp, 1000)); carry = fQuotient(temp, 60); this.setSecond((short)modulo(temp , 60)); } catch (UnsupportedOperationException e) { carry = fQuotient(temp, 60); this.setMinute((short)modulo(temp , 60)); } catch (UnsupportedOperationException e) { carry = fQuotient(temp, 24); this.setHour((short)modulo(temp , 24)); } catch (UnsupportedOperationException e) {
tempDate1 = clone(this); if (tempDate1.isUTC()) { tempDate1.normalize(); tempDate2 = clone(dateTime); if (tempDate2.isUTC()) { tempDate2.normalize(); if (tempDate1.isUTC() == tempDate2.isUTC()) { return compareFields(tempDate1, tempDate2); if (tempDate1.isUTC()) { tempDate2.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate2.normalize(); int result = compareFields(tempDate1, tempDate2); if (result == LESS_THAN) { return result; tempDate2.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate2.setZoneNegative(true); tempDate2.normalize(); tempDate2.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate2.setZoneNegative(true); tempDate2.normalize(); result = compareFields(tempDate1, tempDate2); if (result == GREATER_THAN) { return result;
protected void appendDateString(StringBuffer result) { if (isNegative()) { result.append('-'); } if ((this.getCentury() / 10) == 0) { result.append(0); } result.append(this.getCentury()); if ((this.getYear() / 10) == 0) { result.append(0); } result.append(this.getYear()); result.append('-'); if ((this.getMonth() / 10) == 0) { result.append(0); } result.append(this.getMonth()); result.append('-'); if ((this.getDay()/10) == 0) { result.append(0); } result.append(this.getDay()); }
/** * Normalizes a date/time datatype as defined in W3C XML Schema * Recommendation document: if a timeZone is present but it is not Z then we * convert the date/time datatype to Z using the addition operation defined * in <a * href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> * Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E).</a> * * @see #addDuration */ public void normalize() { if (!isUTC() || (_zoneHour == 0 && _zoneMinute == 0)) { return; } Duration temp = new Duration(); temp.setHour(_zoneHour); temp.setMinute(_zoneMinute); if (isZoneNegative()) { temp.setNegative(); } this.addDuration(temp); //reset the zone this.setZone((short)0, (short)0); this.setZoneNegative(false); }
protected void appendTimeString(StringBuffer result) { if ((this.getHour()/10) == 0) { result.append(0); } result.append(this.getHour()); result.append(':'); if ((this.getMinute() / 10) == 0) { result.append(0); } result.append(this.getMinute()); result.append(':'); if ((this.getSeconds() / 10) == 0) { result.append(0); } result.append(this.getSeconds()); if (this.getMilli() != 0) { result.append('.'); if (this.getMilli() < 100){ result.append('0'); if (this.getMilli() < 10){ result.append('0'); } } result.append(this.getMilli()); } }
int comparison = dateTime.compareTo(_fixed); if (comparison == DateTimeBase.INDETERMINATE) { String err = dateTime.getClass().getName() + " " + dateTime if (isThereMinInclusive && dateTime.compareTo(_minInclusive) != DateTimeBase.GREATER_THAN && !dateTime.equals(_minInclusive)) { String err = dateTime.getClass().getName() + " " + dateTime + " is less than the minimum allowed value: " + _minInclusive; if (isThereMinExclusive && dateTime.compareTo(_minExclusive) != DateTimeBase.GREATER_THAN) { String err = dateTime.getClass().getName() + " " + dateTime + " is less than or equal to the minimum (exclusive) value: " + _minExclusive; if (isThereMaxInclusive && dateTime.compareTo(_maxInclusive) != DateTimeBase.LESS_THAN && !dateTime.equals(_maxInclusive)) { String err = dateTime.getClass().getName() + " " + dateTime + " is greater than the maximum allowed value: " + _maxInclusive; if (isThereMaxExclusive && dateTime.compareTo(_maxExclusive) != DateTimeBase.LESS_THAN) { String err = dateTime.getClass().getName() + " " + dateTime + " is greater than or equal to the maximum (exclusive) value: "
/** * Helper function defined in W3C XML Schema Recommendation part 2. * @see <a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes"> * W3C XML Schema Recommendation part 2</a> */ private int modulo(int a, int b) { return a - fQuotient(a,b) * b; }
/** * Returns true if the present instance of date/time type is equal to the * parameter. * <p> * The equals relation is as defined in the W3C XML Schema Recommendation, * part2. * * @param dateTime * the date/time type to compare with the present instance * @return true if the present instance is equal to the parameter false if * not */ protected boolean equal(DateTimeBase dateTime) { return EQUALS == this.compareTo(dateTime); } //equals