use of org.bedework.calfacade.base.BwTimeRange in project bw-calendar-engine by Bedework.
the class CalDavParseUtil method parseBwTimeRange.
/**
* The given node must be a time-range element
* <!ELEMENT time-range EMPTY>
*
* <!ATTLIST time-range start CDATA
* end CDATA>
*
* e.g. <C:time-range start="20040902T000000Z"
* end="20040902T235959Z"/>
*
* @param nd
* @param tzid - timezone to use if specified
* @return TimeRange
* @throws CalFacadeException
*/
public static BwTimeRange parseBwTimeRange(Node nd, String tzid) throws CalFacadeException {
BwDateTime start = null;
BwDateTime end = null;
NamedNodeMap nnm = nd.getAttributes();
if ((nnm == null) || (nnm.getLength() == 0)) {
// Infinite time-range?
throw new CalFacadeBadRequest("Infinite time range");
}
int attrCt = nnm.getLength();
try {
Node nmAttr = nnm.getNamedItem("start");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
start = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
start = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
nmAttr = nnm.getNamedItem("end");
if (nmAttr != null) {
attrCt--;
if (tzid == null) {
end = BwDateTimeUtil.getDateTimeUTC(nmAttr.getNodeValue());
} else {
end = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(), false, false, tzid);
}
}
} catch (Throwable t) {
throw new CalFacadeBadRequest(t);
}
if (attrCt != 0) {
throw new CalFacadeBadRequest();
}
return new BwTimeRange(start, end);
}
use of org.bedework.calfacade.base.BwTimeRange in project bw-calendar-engine by Bedework.
the class BwDateTimeUtil method getPeriod.
/**
* Get a date/time range given by the rfc formatted parameters and limited to
* the given max range
*
* @param start
* @param end
* @param defaultField
* @param defaultVal
* @param maxField
* @param maxVal - 0 for no max
* @return TimeRange or null for bad request
* @throws CalFacadeException
*/
public static BwTimeRange getPeriod(final String start, final String end, final int defaultField, final int defaultVal, final int maxField, final int maxVal) throws CalFacadeException {
Locale loc = BwLocale.getLocale();
Calendar startCal = Calendar.getInstance(loc);
startCal.set(Calendar.HOUR_OF_DAY, 0);
startCal.set(Calendar.MINUTE, 0);
startCal.set(Calendar.SECOND, 0);
Calendar endCal = Calendar.getInstance(loc);
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
if (start != null) {
startCal.setTime(fromDate(start));
}
if (end == null) {
endCal.setTime(startCal.getTime());
endCal.add(defaultField, defaultVal);
} else {
endCal.setTime(fromDate(end));
}
// Don't allow more than the max
if (maxVal > 0) {
Calendar check = Calendar.getInstance(loc);
check.setTime(startCal.getTime());
check.add(maxField, maxVal);
if (check.before(endCal)) {
return null;
}
}
BwTimeRange tr = new BwTimeRange(BwDateTimeUtil.getDateTime(DateTimeUtil.isoDateTime(startCal.getTime()), false, // floating
false, // tzid
null), BwDateTimeUtil.getDateTime(DateTimeUtil.isoDateTime(endCal.getTime()), false, // floating
false, // tzid
null));
return tr;
}
Aggregations