Пример #1
0
 /**
  * Convert an {@link XMLGregorianCalendar} (assumed to be in UTC) into a {@link DateTime}.
  *
  * @param soapTime the UTC timestamp extracted from the SF soap layer
  * @return a DateTime object representing the same time as the original soapTime
  */
 public static DateTime convertSFTimeToDateTime(XMLGregorianCalendar soapTime) {
   return new DateTime(
       soapTime.getYear(),
       soapTime.getMonth(),
       soapTime.getDay(),
       soapTime.getHour(),
       soapTime.getMinute(),
       soapTime.getSecond(),
       soapTime.getMillisecond(),
       DateTimeZone.UTC);
 }
Пример #2
0
  private static void checkXmlGregorianCalendarFieldRef(QName type, XMLGregorianCalendar cal)
      throws javax.xml.bind.MarshalException {
    StringBuffer buf = new StringBuffer();
    int bitField = xmlGregorianCalendarFieldRef.get(type);
    final int l = 0x1;
    int pos = 0;
    while (bitField != 0x0) {
      int bit = bitField & l;
      bitField >>>= 4;
      pos++;

      if (bit == 1) {
        switch (pos) {
          case 1:
            if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_SEC);
            }
            break;
          case 2:
            if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_MIN);
            }
            break;
          case 3:
            if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_HR);
            }
            break;
          case 4:
            if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_DAY);
            }
            break;
          case 5:
            if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_MONTH);
            }
            break;
          case 6:
            if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED) {
              buf.append("  " + Messages.XMLGREGORIANCALENDAR_YEAR);
            }
            break;
          case 7: // ignore timezone setting
            break;
        }
      }
    }
    if (buf.length() > 0) {
      throw new javax.xml.bind.MarshalException(
          Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart()) + buf.toString());
    }
  }
  private XMLGregorianCalendar getCurrentTime() {
    // get the current time and set the eventTime
    XMLGregorianCalendar now = null;
    try {
      DatatypeFactory dataFactory = DatatypeFactory.newInstance();
      now = dataFactory.newXMLGregorianCalendar(new GregorianCalendar());
      log.debug(
          "Event Time:"
              + now.getHour()
              + ":"
              + now.getMinute()
              + ":"
              + ":"
              + now.getSecond()
              + "\n");
    } catch (DatatypeConfigurationException e) {
      e.printStackTrace();
    }

    return now;
  }
 public int getPart(int part) {
   switch (part) {
     case YEAR:
       return calendar.getYear();
     case MONTH:
       return calendar.getMonth();
     case DAY:
       return calendar.getDay();
     case HOUR:
       return calendar.getHour();
     case MINUTE:
       return calendar.getMinute();
     case SECOND:
       return calendar.getSecond();
     case MILLISECOND:
       int mSec = calendar.getMillisecond();
       if (mSec == DatatypeConstants.FIELD_UNDEFINED) return 0;
       else return calendar.getMillisecond();
     default:
       throw new IllegalArgumentException("Invalid argument to method getPart");
   }
 }
Пример #5
0
 public int getSecond() {
   return calendar.getSecond();
 }