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); } }
public Metadata encodeMetadata() { Metadata meta = new Metadata(); meta.put(FN_START, mStart.getDateTimePartString(false)); if (mHasEnd) meta.put(FN_END, mEnd.getDateTimePartString(false)); else meta.put(FN_DURATION, mDuration); return meta; }
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(); }
private static IRecurrence getRecurrenceForDay( int dayOfWeek, StartSpec startSpec, TimeRange timeRange, ICalTimeZone tz, TimeZoneMap tzmap) throws ServiceException { // DTSTART String dateStr = startSpec.getDateString(dayOfWeek); String dtStartStr; if (tz.sameAsUTC()) dtStartStr = String.format("%sT%02d%02d00Z", dateStr, timeRange.start.hour, timeRange.start.minute); else dtStartStr = String.format( "TZID=\"%s\":%sT%02d%02d00", tz.getID(), dateStr, timeRange.start.hour, timeRange.start.minute); ParsedDateTime dtStart; try { dtStart = ParsedDateTime.parse(dtStartStr, tzmap); } catch (ParseException e) { throw ServiceException.INVALID_REQUEST("Bad date/time value \"" + dtStartStr + "\"", e); } // DURATION ParsedDuration dur = timeRange.getDuration(); // RRULE String dayName = DayOfWeekName.lookup(dayOfWeek); String ruleStr = String.format("FREQ=WEEKLY;INTERVAL=1;BYDAY=%s", dayName); return new Recurrence.SimpleRepeatingRule(dtStart, dur, new ZRecur(ruleStr, tzmap), null); }
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); } }
public Period(ParsedDateTime start, ParsedDuration dur) { mStart = start; mDuration = dur; mEnd = mStart.add(mDuration); mHasEnd = false; }
public Period(ParsedDateTime start, ParsedDateTime end) { mStart = start; mEnd = end; mDuration = mEnd.difference(mStart); mHasEnd = true; }