protected XMLGregorianCalendar parseTerminationTime(String value) {
   try {
     Duration d = datatypeFactory.newDuration(value);
     XMLGregorianCalendar c = getCurrentTime();
     c.add(d);
     return c;
   } catch (Exception e) {
     // Ignore
   }
   try {
     Duration d = datatypeFactory.newDurationDayTime(value);
     XMLGregorianCalendar c = getCurrentTime();
     c.add(d);
     return c;
   } catch (Exception e) {
     // Ignore
   }
   try {
     Duration d = datatypeFactory.newDurationYearMonth(value);
     XMLGregorianCalendar c = getCurrentTime();
     c.add(d);
     return c;
   } catch (Exception e) {
     // Ignore
   }
   try {
     return datatypeFactory.newXMLGregorianCalendar(value);
   } catch (Exception e) {
     // Ignore
   }
   return null;
 }
Esempio n. 2
0
  /**
   * Add additional time in miliseconds
   *
   * @param value calendar whose value needs to be updated
   * @param milis
   * @return calendar value with the addition
   * @throws ConfigurationException
   */
  public static XMLGregorianCalendar add(XMLGregorianCalendar value, long milis)
      throws ConfigurationException {
    XMLGregorianCalendar newVal = (XMLGregorianCalendar) value.clone();

    Duration duration;
    try {
      duration = newDatatypeFactory().newDuration(milis);
    } catch (DatatypeConfigurationException e) {
      throw logger.configurationError(e);
    }
    newVal.add(duration);
    return newVal;
  }
Esempio n. 3
0
 @Mapping(from = Integer.class, to = XMLGregorianCalendar.class)
 public static synchronized XMLGregorianCalendar map(
     BigDecimal secondsAgo, XMLGregorianCalendar template) {
   GregorianCalendar calendar =
       template != null
           ? template.toGregorianCalendar()
           : new GregorianCalendar(TimeZone.getTimeZone("UTC"));
   DatatypeFactory factory = getDatatypeFactory();
   XMLGregorianCalendar ret = null;
   if (factory != null) {
     ret = factory.newXMLGregorianCalendar(calendar);
     ret.add(factory.newDuration(false, 0, 0, 0, 0, 0, secondsAgo.intValue()));
   }
   return ret;
 }
 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);
 }
Esempio n. 5
0
 public void add(Duration duration) {
   calendar.add(duration);
 }