/** Return a BwDuration populated from the given String value. * * @param val String * @return BwDuration * @throws CalFacadeException */ public static BwDuration makeDuration(final String val) throws CalFacadeException { BwDuration db = new BwDuration(); populate(db, val); return db; }
@Override public String toString() { StringBuffer sb = new StringBuffer(); if (negative) { sb.append("-"); } sb.append("P"); if (getWeeks() != 0) { sb.append(getWeeks()); sb.append("W"); } else { if (getDays() != 0) { sb.append(getDays()); sb.append("D"); } boolean addedT = false; addedT = addTimeComponent(sb, getHours(), "H", addedT); addedT = addTimeComponent(sb, getMinutes(), "M", addedT); addedT = addTimeComponent(sb, getSeconds(), "S", addedT); } return sb.toString(); }
/** Return true if this represents a zero duration * * @return boolean */ public boolean isZero() { if (getWeeks() != 0) { return false; } return ((getDays() == 0) && (getHours() == 0) && (getMinutes() == 0) && (getSeconds() == 0)); }
/** Populate the bean from the given String value. * * @param db BwDuration * @param val String value * @throws CalFacadeException */ public static void populate(final BwDuration db, final String val) throws CalFacadeException { try { if (val == null) { return; } Dur d = new Dur(val); if (d.getWeeks() != 0) { db.setWeeks(d.getWeeks()); return; } db.setDays(d.getDays()); db.setHours(d.getHours()); db.setMinutes(d.getMinutes()); db.setSeconds(d.getSeconds()); db.setNegative(d.isNegative()); } catch (Throwable t) { throw new CalFacadeException("Invalid duration"); } }
/** Return a BwDuration populated from the String duration. * * @return BwDuration * @throws CalFacadeException */ @NoProxy public BwDuration makeDurationBean() throws CalFacadeException { return BwDuration.makeDuration(getDuration()); }
/** Return a value based on this value plus a duration. * * @param val * @return BwDateTime * @throws CalFacadeException */ public BwDateTime addDuration(final BwDuration val) throws CalFacadeException { return addDuration(val.makeDuration().getDuration()); }
/** Make an ical Duration * * @return Duration */ public Duration makeDuration() { Dur d; if (weeks != 0) { d = new Dur(getWeeks()); } else { d = new Dur(getDays(), getHours(), getMinutes(), getSeconds()); } return new Duration(d); }
public BwDuration makeDurationBean() throws CalFacadeException { String duration = ref.getDuration(); if (duration == null) { duration = getTarget().getDuration(); } return BwDuration.makeDuration(duration); }
/** Generate a recurrence instance for the given master event * based on the recurrenceId and the date/time info in the master. * * @param master event * @param recurrenceId for the instance. * @return instance object filled in. * @throws CalFacadeException */ public static BwRecurrenceInstance fromRecurrencId(final BwEvent master, String recurrenceId) throws CalFacadeException { final String stzid = master.getDtstart().getTzid(); final boolean dateOnly = master.getDtstart().getDateType(); final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, recurrenceId, stzid); final BwDateTime rend = rstart.addDuration( BwDuration.makeDuration(master.getDuration())); final BwRecurrenceInstance ri = new BwRecurrenceInstance(); ri.setDtstart(rstart); ri.setDtend(rend); ri.setRecurrenceId(ri.getDtstart().getDate()); ri.setMaster(master); return ri; }