protected static int parseTimeZone(final String str, final DateTimeBase result, final char[] chars, final int index, final String complaint) throws ParseException { // If we're at the end of the string, there's no time zone to parse if (index >= chars.length) { return index; } int idx = index; if (chars[idx] == 'Z') { result.setUTC(); return ++idx; } if (chars[idx] == '+' || chars[idx] == '-') { if (chars[idx] == '-') { result.setZoneNegative(true); } idx++; if (idx + 5 > chars.length || chars[idx + 2] != ':' || !Character.isDigit(chars[idx]) || !Character.isDigit(chars[idx + 1]) || !Character.isDigit(chars[idx + 3]) || !Character.isDigit(chars[idx + 4])) { throw new ParseException(complaint + str + "\nTimeZone must have the format (+/-)hh:mm", idx); } short value1 = (short) ((chars[idx] - '0') * 10 + (chars[idx + 1] - '0')); short value2 = (short) ((chars[idx + 3] - '0') * 10 + (chars[idx + 4] - '0')); result.setZone(value1, value2); idx += 5; } return idx; }
protected static int parseTimeZone(final String str, final DateTimeBase result, final char[] chars, final int index, final String complaint) throws ParseException { // If we're at the end of the string, there's no time zone to parse if (index >= chars.length) { return index; } int idx = index; if (chars[idx] == 'Z') { result.setUTC(); return ++idx; } if (chars[idx] == '+' || chars[idx] == '-') { if (chars[idx] == '-') { result.setZoneNegative(true); } idx++; if (idx + 5 > chars.length || chars[idx + 2] != ':' || !Character.isDigit(chars[idx]) || !Character.isDigit(chars[idx + 1]) || !Character.isDigit(chars[idx + 3]) || !Character.isDigit(chars[idx + 4])) { throw new ParseException(complaint+str+"\nTimeZone must have the format (+/-)hh:mm", idx); } short value1 = (short) ((chars[idx] - '0') * 10 + (chars[idx+1] - '0')); short value2 = (short) ((chars[idx+3] - '0') * 10 + (chars[idx+4] - '0')); result.setZone(value1,value2); idx += 5; } return idx; }
public DateTimeBase clone(DateTimeBase dateTime) throws CloneNotSupportedException { DateTimeBase newDateTime = (DateTimeBase) super.clone(); // newDateTime = (DateTimeBase) dateTime.getClass().newInstance(); newDateTime.setValues(dateTime.getValues()); if (dateTime.hasIsNegative() && dateTime.isNegative()) { newDateTime.setNegative(); } if (dateTime.isUTC()) { newDateTime.setUTC(); newDateTime.setZone(dateTime.getZoneHour(), dateTime.getZoneMinute()); newDateTime.setZoneNegative(dateTime.isZoneNegative()); } return newDateTime; }
public DateTimeBase clone(DateTimeBase dateTime) throws CloneNotSupportedException { DateTimeBase newDateTime = (DateTimeBase) super.clone(); // newDateTime = (DateTimeBase) dateTime.getClass().newInstance(); newDateTime.setValues(dateTime.getValues()); if (dateTime.hasIsNegative() && dateTime.isNegative()) { newDateTime.setNegative(); } if (dateTime.isUTC()) { newDateTime.setUTC(); newDateTime.setZone(dateTime.getZoneHour(), dateTime.getZoneMinute()); newDateTime.setZoneNegative(dateTime.isZoneNegative()); } return newDateTime; }
tempDate2.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate2.normalize(); int result = compareFields(tempDate1, tempDate2); 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(); tempDate1.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate1.normalize(); int result = compareFields(tempDate1, tempDate2); tempDate1.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate1.setZoneNegative(true); tempDate1.normalize(); tempDate1.setZone((short) MAX_TIME_ZONE_COMPARISON_OFFSET, (short) 0); tempDate1.setZoneNegative(true); tempDate1.normalize();
tempDate2.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate2.normalize(); int result = compareFields(tempDate1, tempDate2); 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(); tempDate1.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate1.normalize(); int result = compareFields(tempDate1, tempDate2); tempDate1.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate1.setZoneNegative(true); tempDate1.normalize(); tempDate1.setZone((short)MAX_TIME_ZONE_COMPARISON_OFFSET,(short)0); tempDate1.setZoneNegative(true); tempDate1.normalize();
/** * 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); }
/** * 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); }