コード例 #1
0
 /**
  * Return a calendar with the timezone field set, to be used for order comparison. If the original
  * calendar did not specify a timezone, set the local timezone (unadjusted for daylight savings).
  * The returned calendars will be totally ordered between themselves. We also set any missing
  * fields to ensure that normalization doesn't discard important data! (This is probably a bug in
  * the JAXP implementation, but the workaround doesn't hurt us, so it's faster to just fix it
  * here.)
  *
  * @return the calendar represented by this object, with the timezone field filled in with an
  *     implicit value if necessary
  */
 protected XMLGregorianCalendar getImplicitCalendar() {
   if (implicitCalendar == null) {
     implicitCalendar = (XMLGregorianCalendar) calendar.clone();
     if (calendar.getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
       implicitCalendar.setTimezone(TimeUtils.getInstance().getLocalTimezoneOffsetMinutes());
     }
     // fill in fields from default reference; don't have to worry about weird combinations of
     // fields being set, since we control that on creation
     switch (getType()) {
       case Type.DATE:
         implicitCalendar.setTime(0, 0, 0);
         break;
       case Type.TIME:
         implicitCalendar.setYear(1972);
         implicitCalendar.setMonth(12);
         implicitCalendar.setDay(31);
         break;
       default:
     }
     implicitCalendar =
         implicitCalendar
             .normalize(); // the comparison routines will normalize it anyway, just do it once
                           // here
   }
   return implicitCalendar;
 }
コード例 #2
0
 public AbstractDateTimeValue adjustedToTimezone(DayTimeDurationValue offset)
     throws XPathException {
   if (offset == null)
     offset = new DayTimeDurationValue(TimeUtils.getInstance().getLocalTimezoneOffsetMillis());
   validateTimezone(offset);
   XMLGregorianCalendar xgc = (XMLGregorianCalendar) calendar.clone();
   if (xgc.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
     if (getType() == Type.DATE)
       xgc.setTime(0, 0, 0); // set the fields so we don't lose precision when shifting timezones
     xgc = xgc.normalize();
     xgc.add(offset.duration);
   }
   try {
     xgc.setTimezone((int) (offset.getValue() / 60));
   } catch (IllegalArgumentException e) {
     throw new XPathException("illegal timezone offset " + offset, e);
   }
   return createSameKind(xgc);
 }
コード例 #3
0
 private Object encodeLiteral(final Literal literal) {
   final URI datatype = literal.getDatatype();
   if (datatype == null || datatype.equals(XMLSchema.STRING)) {
     final String language = literal.getLanguage();
     if (language == null) {
       return literal.getLabel();
     } else {
       return SerializerAvro.newGenericRecord(Schemas.STRING_LANG, literal.getLabel(), language);
     }
   } else if (datatype.equals(XMLSchema.BOOLEAN)) {
     return literal.booleanValue();
   } else if (datatype.equals(XMLSchema.LONG)) {
     return literal.longValue();
   } else if (datatype.equals(XMLSchema.INT)) {
     return literal.intValue();
   } else if (datatype.equals(XMLSchema.DOUBLE)) {
     return literal.doubleValue();
   } else if (datatype.equals(XMLSchema.FLOAT)) {
     return literal.floatValue();
   } else if (datatype.equals(XMLSchema.SHORT)) {
     return SerializerAvro.newGenericRecord(Schemas.SHORT, literal.intValue());
   } else if (datatype.equals(XMLSchema.BYTE)) {
     return SerializerAvro.newGenericRecord(Schemas.BYTE, literal.intValue());
   } else if (datatype.equals(XMLSchema.INTEGER)) {
     return SerializerAvro.newGenericRecord(Schemas.BIGINTEGER, literal.stringValue());
   } else if (datatype.equals(XMLSchema.DECIMAL)) {
     return SerializerAvro.newGenericRecord(Schemas.BIGDECIMAL, literal.stringValue());
   } else if (datatype.equals(XMLSchema.DATETIME)) {
     final XMLGregorianCalendar calendar = literal.calendarValue();
     return SerializerAvro.newGenericRecord(
         Schemas.CALENDAR,
         calendar.getTimezone(),
         calendar.toGregorianCalendar().getTimeInMillis());
   }
   throw new IllegalArgumentException("Unsupported literal: " + literal);
 }
コード例 #4
0
ファイル: PsiXmlCalendar.java プロジェクト: arnaudceol/psimi
 public int getTimezone() {
   return calendar.getTimezone();
 }
コード例 #5
0
 public Sequence getTimezone() throws XPathException {
   int tz = calendar.getTimezone();
   if (tz == DatatypeConstants.FIELD_UNDEFINED) return Sequence.EMPTY_SEQUENCE;
   return new DayTimeDurationValue(tz * 60000L);
 }