예제 #1
0
 public DurationInfo(ParsedDuration parsedDuration) {
   this.weeks = adjustDuration(parsedDuration.getWeeks());
   if (this.weeks == null) {
     this.days = adjustDuration(parsedDuration.getDays());
     this.hours = adjustDuration(parsedDuration.getHours());
     this.minutes = adjustDuration(parsedDuration.getMins());
     this.seconds = adjustDuration(parsedDuration.getSecs());
   }
 }
예제 #2
0
  public static Period decodeMetadata(Metadata meta, ICalTimeZone tz, TimeZoneMap tzmap)
      throws ServiceException {
    String start = meta.get(FN_START);
    ParsedDateTime startTime;
    try {
      startTime = ParsedDateTime.parse(start, tzmap, tz, tzmap.getLocalTimeZone());
    } catch (ParseException e) {
      throw ServiceException.INVALID_REQUEST(
          "Invalid PERIOD start time in metadata: " + meta.toString(), e);
    }

    String end = meta.get(FN_END, null);
    if (end != null) {
      ParsedDateTime endTime;
      try {
        endTime = ParsedDateTime.parse(end, tzmap, tz, tzmap.getLocalTimeZone());
      } catch (ParseException e) {
        throw ServiceException.INVALID_REQUEST(
            "Invalid PERIOD end time in metadata: " + meta.toString(), e);
      }
      return new Period(startTime, endTime);
    } else {
      String durStr = meta.get(FN_DURATION, null);
      if (durStr == null)
        throw ServiceException.INVALID_REQUEST(
            "PERIOD in metadata missing both end time and duration: " + meta.toString(), null);
      ParsedDuration duration = ParsedDuration.parse(durStr);
      return new Period(startTime, duration);
    }
  }
예제 #3
0
 public String toString() {
   StringBuilder sb = new StringBuilder(mStart.getDateTimePartString(false));
   sb.append("/");
   if (mHasEnd) {
     if (mEnd != null) sb.append(mEnd.getDateTimePartString(false));
   } else {
     if (mDuration != null) sb.append(mDuration.toString());
   }
   return sb.toString();
 }
예제 #4
0
  public static Period parse(String value, ICalTimeZone tz, TimeZoneMap tzmap)
      throws ServiceException, ParseException {
    String parsed[] = value.split("\\/", 2);
    if (parsed.length != 2 || parsed[0].length() == 0 || parsed[1].length() == 1)
      throw ServiceException.INVALID_REQUEST("Invalid PERIOD value \"" + value + "\"", null);

    ParsedDateTime startTime;
    startTime = ParsedDateTime.parse(parsed[0], tzmap, tz, tzmap.getLocalTimeZone());

    char ch = parsed[1].charAt(0);
    if (ch == 'P' || ch == '+' || ch == '-') {
      ParsedDuration duration = ParsedDuration.parse(parsed[1]);
      return new Period(startTime, duration);
    } else {
      ParsedDateTime endTime = ParsedDateTime.parse(parsed[1], tzmap, tz, tzmap.getLocalTimeZone());
      return new Period(startTime, endTime);
    }
  }
예제 #5
0
 public ParsedDuration getDuration() {
   int diff = end.hour * 60 + end.minute - (start.hour * 60 + start.minute);
   int hours = diff / 60;
   int minutes = diff % 60;
   return ParsedDuration.parse(false, 0, 0, hours, minutes, 0);
 }