/**
  * 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;
 }
 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);
 }
 public static String createSamplePayload() throws Exception {
   JAXBContext jaxbContext = JAXBContext.newInstance("pl.edu.agh.security.delivery.pojos");
   Marshaller marshaller = jaxbContext.createMarshaller();
   ObjectFactory objectFactory = new ObjectFactory();
   DeliveryRequest deliveryRequest = objectFactory.createDeliveryRequest();
   XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar();
   xgc.setYear(2013);
   xgc.setMonth(DatatypeConstants.JUNE);
   xgc.setDay(2);
   xgc.setTime(15, 10, 1);
   deliveryRequest.setCompletionDateTime(xgc);
   deliveryRequest.setPriority(Priority.TOP);
   deliveryRequest.setRecipientAddress("Springfield 123");
   deliveryRequest.setRecipientName("Homer Simpson");
   deliveryRequest.setSenderAddress("Southpark 456");
   deliveryRequest.setSenderName("Eric Cartman");
   deliveryRequest.setWeight(BigDecimal.TEN);
   StringWriter sw = new StringWriter();
   marshaller.marshal(objectFactory.createDeliveryRequest(deliveryRequest), sw);
   return sw.toString();
 }
Example #4
0
 public void setTime(int hour, int minute, int second) {
   calendar.setTime(hour, minute, second);
 }
Example #5
0
 public void setTime(int hour, int minute, int second, BigDecimal fractional) {
   calendar.setTime(hour, minute, second, fractional);
 }