use of org.bedework.calfacade.exc.CalFacadeBadDateException 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.calfacade.exc.CalFacadeBadDateException in project bw-calendar-engine by Bedework.
the class BwDateTime method fromUTC.
/**
* Create from utc time with timezone
*
* @param dateType true for a date value
* @param date the string UTC date/time or 8 character date
* @param tzid tzid for local time
* @return initialised BwDateTime
* @throws CalFacadeException
*/
public static BwDateTime fromUTC(final boolean dateType, final String date, final String tzid) throws CalFacadeException {
if (!dateType && !date.endsWith("Z")) {
throw new CalFacadeBadDateException();
}
try {
final BwDateTime bwd = new BwDateTime();
bwd.setDateType(dateType);
if (dateType | (tzid == null)) {
bwd.setDtval(date);
bwd.setTzid(null);
} else {
final java.util.Date dt = DateTimeUtil.fromISODateTimeUTC(date);
bwd.setDtval(DateTimeUtil.isoDateTime(dt, Timezones.getTz(tzid)));
bwd.setTzid(tzid);
}
if (dateType) {
bwd.setDate(date + "T000000Z");
} else {
bwd.setDate(date);
}
return bwd;
} catch (final Throwable t) {
throw new CalFacadeBadDateException();
}
}
use of org.bedework.calfacade.exc.CalFacadeBadDateException 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