use of org.bedework.util.timezones.TimezonesException in project bw-calendar-engine by Bedework.
the class BwDateTime method makeBwDateTime.
/**
* Constructor
*
* @param dateType
* @param date
* @param tzid
* @return initialised BwDateTime
* @throws CalFacadeException
*/
public static BwDateTime makeBwDateTime(final boolean dateType, final String date, final String tzid) throws CalFacadeException {
try {
if (dateType) {
if (!DateTimeUtil.isISODate(date)) {
throw new CalFacadeException("org.bedework.datetime.expect.dateonly");
}
}
BwDateTime bwd = new BwDateTime();
bwd.setDateType(dateType);
bwd.setDtval(date);
bwd.setTzid(tzid);
if (tzid == null) {
if (DateTimeUtil.isISODateTime(date)) {
bwd.setFloatFlag(true);
bwd.setDate(date + "Z");
}
}
if (!bwd.getFloating()) {
bwd.setDate(Timezones.getUtc(date, tzid));
}
return bwd;
} catch (TimezonesException tze) {
if (tze.getMessage().equals(TimezonesException.unknownTimezone)) {
throw new CalFacadeException(CalFacadeException.unknownTimezone, tze.getExtra());
} else {
throw new CalFacadeBadDateException();
}
} catch (Throwable t) {
throw new CalFacadeBadDateException();
}
}
use of org.bedework.util.timezones.TimezonesException in project bw-calendar-engine by Bedework.
the class BwDateTimeUtil method getDateTime.
/**
* Get a date object representing the given date and flags
*
* @param date String iso date or date/time
* @param dateOnly
* @param floating boolean true if this is a floating time
* @param tzid - String tzid or null for default, UTC or floating.
* @return Date object representing the date
* @throws CalFacadeException
*/
public static BwDateTime getDateTime(String date, final boolean dateOnly, final boolean floating, String tzid) throws CalFacadeException {
try {
TimeZone tz = null;
if (dateOnly || floating) {
tzid = null;
}
if (tzid != null) {
tz = Timezones.getTz(tzid);
if (tz == null) {
throw new CalFacadeException(CalFacadeException.unknownTimezone, tzid);
}
} else if (!floating) {
// Asking for default
tzid = Timezones.getThreadDefaultTzid();
tz = Timezones.getDefaultTz();
}
if (DateTimeUtil.isISODateTimeUTC(date)) {
// Convert to local time (relative to supplied timezone)
Date dt = DateTimeUtil.fromISODateTimeUTC(date);
date = DateTimeUtil.isoDateTime(dt, tz);
}
return BwDateTime.makeBwDateTime(dateOnly, date, tzid);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (TimezonesException tze) {
throw new CalFacadeException(tze);
} catch (Throwable t) {
throw new CalFacadeBadDateException();
}
}
Aggregations