Search in sources :

Example 1 with TimezonesException

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();
    }
}
Also used : TimezonesException(org.bedework.util.timezones.TimezonesException) CalFacadeBadDateException(org.bedework.calfacade.exc.CalFacadeBadDateException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with TimezonesException

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();
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) TimezonesException(org.bedework.util.timezones.TimezonesException) CalFacadeBadDateException(org.bedework.calfacade.exc.CalFacadeBadDateException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Date(java.util.Date)

Aggregations

CalFacadeBadDateException (org.bedework.calfacade.exc.CalFacadeBadDateException)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 TimezonesException (org.bedework.util.timezones.TimezonesException)2 Date (java.util.Date)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1