Пример #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());
    }
  }
 /**
  * Utility method that is able to clone a calendar whose year is 0 (whatever a year 0 means). It
  * looks like the JDK is unable to do that.
  *
  * @param calendar The Calendar to clone
  * @return the cloned Calendar
  */
 public static XMLGregorianCalendar cloneXMLGregorianCalendar(XMLGregorianCalendar calendar) {
   boolean hacked = false;
   if (calendar.getYear() == 0) {
     calendar.setYear(1);
     hacked = true;
   }
   XMLGregorianCalendar result = (XMLGregorianCalendar) calendar.clone();
   if (hacked) {
     // reset everything
     calendar.setYear(0);
     // -1 could also be considered
     result.setYear(0);
   }
   return result;
 }
 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;
 }
Пример #5
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");
   }
 }
  @PostConstruct
  public void init() {
    // load dates
    List<XMLGregorianCalendar> gregDates =
        UFOService.getInstance().getDatesWithPerformances().getDateTime();
    for (XMLGregorianCalendar d : gregDates) {
      if (d.getYear() >= Calendar.getInstance().get(Calendar.YEAR)) {
        dates.add(d.toGregorianCalendar().getTime());
      }
    }

    // times to display
    times = new ArrayList<>();
    for (int t = 14; t <= 23; ++t) {
      times.add(t % 24);
    }

    // artists / venues / performances
    reload();

    // category / country
    categories = UFOService.getInstance().getAllCategories().getCategory();
    countries = UFOService.getInstance().getAllCountries().getCountry();
  }
Пример #8
0
 public Integer[] getValue() {
   return new Integer[] {date.getYear(), date.getMonth()};
 }
Пример #9
0
 public int getYear() {
   return date.getYear();
 }
Пример #10
0
 public int getYear() {
   return calendar.getYear();
 }