Example #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);
 }
Example #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 String toStringValue(Object value) {
   if (null == value) return null;
   Date date = null;
   if (value instanceof XMLGregorianCalendar) {
     XMLGregorianCalendar grCal = (XMLGregorianCalendar) value;
     Calendar calendar = Calendar.getInstance();
     calendar.set(Calendar.DAY_OF_MONTH, grCal.getDay());
     calendar.set(Calendar.MONTH, grCal.getMonth() - 1);
     calendar.set(Calendar.YEAR, grCal.getYear());
     date = calendar.getTime();
   } else if (value instanceof Date) {
     date = (Date) value;
   }
   if (null != date) {
     return DateConverter.getFormattedDate(date, DATE_PATTERN);
   }
   return null;
 }
Example #4
0
  public String toXMLFormat() {
    StringBuffer sb = new StringBuffer();

    sb.append(calendar.getYear());
    sb.append("-");
    int month = calendar.getMonth();
    if (month < 10) {
      sb.append("0");
    }
    sb.append(month);
    sb.append("-");
    int day = calendar.getDay();
    if (day < 10) {
      sb.append("0");
    }
    sb.append(day);

    return sb.toString();
  }
 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");
   }
 }
Example #6
0
 public Integer[] getValue() {
   return new Integer[] {date.getYear(), date.getMonth()};
 }
Example #7
0
 public int getMonth() {
   return date.getMonth();
 }
Example #8
0
 public int getMonth() {
   return calendar.getMonth();
 }