Ejemplo n.º 1
0
  private static final Date toDate(String str, Date time) {
    if (str == null) return time;

    Calendar tc = Calendar.getInstance();
    if (time == null) {
      tc.set(Calendar.HOUR_OF_DAY, 0);
      tc.set(Calendar.MINUTE, 0);
      tc.set(Calendar.SECOND, 0);
      tc.set(Calendar.MILLISECOND, 0);
    } else {
      tc.setTime(time);
    }

    str = str.toUpperCase().trim();

    boolean success = false;
    for (int i = 0; i < DATE_FORMATS.length; i++) {
      try {
        Calendar c = Calendar.getInstance();
        KSDateTimeFormatter df = DATE_FORMATS[i];
        c.setTime(df.parse(str));
        tc.set(Calendar.YEAR, c.get(Calendar.YEAR));
        tc.set(Calendar.MONTH, c.get(Calendar.MONTH));
        tc.set(Calendar.DATE, c.get(Calendar.DATE));
        success = true;
        break;
      } catch (IllegalArgumentException e) {
      }
    }

    return success ? tc.getTime() : time;
  }
Ejemplo n.º 2
0
  @Override
  public String getDaysAndTimes() {
    StringBuilder daysAndTimes = new StringBuilder();

    if (monday) daysAndTimes.append(SchedulingServiceConstants.MONDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (tuesday) daysAndTimes.append(SchedulingServiceConstants.TUESDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (wednesday)
      daysAndTimes.append(SchedulingServiceConstants.WEDNESDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (thursday)
      daysAndTimes.append(SchedulingServiceConstants.THURSDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (friday) daysAndTimes.append(SchedulingServiceConstants.FRIDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (saturday)
      daysAndTimes.append(SchedulingServiceConstants.SATURDAY_TIMESLOT_DISPLAY_DAY_CODE);
    if (sunday) daysAndTimes.append(SchedulingServiceConstants.SUNDAY_TIMESLOT_DISPLAY_DAY_CODE);

    KSDateTimeFormatter df = DateFormatters.HOUR_NOZERO_MINUTE_AM_PM_TIME_FORMATTER;
    if (daysAndTimes.length() > 0) daysAndTimes.append(" ");
    daysAndTimes.append(df.format(startDate));
    daysAndTimes.append(" to ");
    daysAndTimes.append(df.format(untilDate));

    return daysAndTimes.toString();
  }
Ejemplo n.º 3
0
  // TODO: KSAP-743 convert these to property editors, add to standard registry
  private static final Date toTime(String str, Date date) {
    if (str == null) return date;

    Calendar dc = Calendar.getInstance();
    if (date == null) {
      dc.set(Calendar.YEAR, 1970);
      dc.set(Calendar.MONTH, Calendar.JANUARY);
      dc.set(Calendar.DATE, 1);
    } else {
      dc.setTime(date);
    }
    dc.set(Calendar.HOUR_OF_DAY, 0);
    dc.set(Calendar.MINUTE, 0);
    dc.set(Calendar.SECOND, 0);
    dc.set(Calendar.MILLISECOND, 0);

    str = str.toUpperCase().trim();
    if (str.endsWith("A") || str.endsWith("P")) str += "M";

    boolean success = false;
    for (int i = 0; i < TIME_FORMATS.length; i++) {
      try {
        Calendar c = Calendar.getInstance();
        KSDateTimeFormatter df = TIME_FORMATS[i];
        c.setTime(df.parse(str));
        if (i == TIME_FORMATS.length - 1)
          if (c.get(Calendar.HOUR_OF_DAY) < 8) c.set(Calendar.AM_PM, Calendar.PM);
        dc.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY));
        dc.set(Calendar.MINUTE, c.get(Calendar.MINUTE));
        success = true;
        break;
      } catch (IllegalArgumentException e) {
      }
    }

    return success ? dc.getTime() : date;
  }