Example usage for org.joda.time Interval parse

List of usage examples for org.joda.time Interval parse

Introduction

In this page you can find the example usage for org.joda.time Interval parse.

Prototype

public static Interval parse(String str) 

Source Link

Document

Parses an Interval from the specified string.

Usage

From source file:org.forgerock.openidm.util.DateUtil.java

License:CDDL license

/**
 * Returns a {@link DateTime} object representing the start date of the supplied interval.
 * //from w  w  w .  java2s  .  co  m
 * @param intervalString a {@link String} object representing an ISO 8601 time interval.
 * @return a {@link DateTime} object representing the start date of the supplied interval.
 * @throws IllegalArgumentException if an error occurs while parsing the intervalString.
 */
public DateTime getStartOfInterval(String intervalString) throws IllegalArgumentException {
    Interval interval = Interval.parse(intervalString);
    DateTime result = interval.getStart();
    return result;
}

From source file:org.forgerock.openidm.util.DateUtil.java

License:CDDL license

/**
 * Returns a {@link DateTime} object representing the end date of the supplied interval.
 * //from  w w w.jav a 2s . c  o m
 * @param intervalString a {@link String} object representing an ISO 8601 time interval.
 * @return a {@link DateTime} object representing the end date of the supplied interval.
 * @throws IllegalArgumentException if an error occurs while parsing the intervalString.
 */
public DateTime getEndOfInterval(String intervalString) throws IllegalArgumentException {
    Interval interval = Interval.parse(intervalString);
    DateTime result = interval.getEnd();
    return result;
}

From source file:org.forgerock.openidm.util.DateUtil.java

License:CDDL license

/**
 * Returns true if the supplied timestamp is within the specified time interval.  The supplied interval string 
 * should contain an ISO 8601 formatted interval string and may be of the formats 'datetime/datetime', 
 * 'datetime/period' or 'period/datetime'
 * //from   w  w w.  j  a  v a  2  s.  com
 * @param timestamp a {@link DateTime} object representing a date time instant.
 * @param intervalString a {@link String} object representing an ISO 8601 time interval.
 * @return true if the instant is within the interval, false otherwise.
 * @throws IllegalArgumentException if an error occurs while parsing the intervalString.
 */
public boolean isTimestampWithinInterval(DateTime timestamp, String intervalString)
        throws IllegalArgumentException {
    Interval interval = Interval.parse(intervalString);
    return interval.contains(timestamp);
}

From source file:org.jasig.portlet.calendar.mvc.controller.CalendarController.java

License:Apache License

@RequestMapping
public ModelAndView getCalendar(@RequestParam(required = false, value = "interval") String intervalString,
        RenderRequest request) {/*  www  . j a v a2  s . c om*/

    PortletSession session = request.getPortletSession(true);

    PortletPreferences prefs = request.getPreferences();

    Map<String, Object> model = new HashMap<String, Object>();

    // get the list of hidden calendars
    @SuppressWarnings("unchecked")
    HashMap<Long, String> hiddenCalendars = (HashMap<Long, String>) session.getAttribute("hiddenCalendars");

    // indicate if the current user is a guest (unauthenticated) user
    model.put("guest", request.getRemoteUser() == null);

    /**
     * Add and remove calendars from the hidden list.  Hidden calendars
     * will be fetched, but rendered invisible in the view.
     */

    // check the request parameters to see if we need to add any
    // calendars to the list of hidden calendars
    String hideCalendar = request.getParameter("hideCalendar");
    if (hideCalendar != null) {
        hiddenCalendars.put(Long.valueOf(hideCalendar), "true");
        session.setAttribute("hiddenCalendars", hiddenCalendars);
    }

    // check the request parameters to see if we need to remove
    // any calendars from the list of hidden calendars
    String showCalendar = request.getParameter("showCalendar");
    if (showCalendar != null) {
        hiddenCalendars.remove(Long.valueOf(showCalendar));
        session.setAttribute("hiddenCalendars", hiddenCalendars);
    }

    // See if we're configured to show or hide the jQueryUI DatePicker.
    // By default, we assume we are to show the DatePicker because that's
    // the classic behavior.
    String showDatePicker = prefs.getValue("showDatePicker", "true");
    model.put("showDatePicker", showDatePicker);

    /**
     * Find our desired starting and ending dates.
     */

    Interval interval = null;

    if (!StringUtils.isEmpty(intervalString)) {
        interval = Interval.parse(intervalString);
        model.put("startDate", new DateMidnight(interval.getStart()).toDate());
        model.put("days", interval.toDuration().getStandardDays());
        model.put("endDate", new DateMidnight(interval.getEnd()));
    } else {
        //StartDate can only be changed via an AJAX request
        DateMidnight startDate = (DateMidnight) session.getAttribute("startDate");
        log.debug("startDate from session is: " + startDate);
        model.put("startDate", startDate.toDate());

        // find how many days into the future we should display events
        int days = (Integer) session.getAttribute("days");
        model.put("days", days);

        // set the end date based on our desired time period
        DateMidnight endDate = startDate.plusDays(days);
        model.put("endDate", endDate.toDate());

        interval = new Interval(startDate, endDate);
    }

    // define "today" and "tomorrow" so we can display these specially in the
    // user interface
    // get the user's configured time zone
    String timezone = (String) session.getAttribute("timezone");
    DateMidnight today = new DateMidnight(DateTimeZone.forID(timezone));
    model.put("today", today.toDate());
    model.put("tomorrow", today.plusDays(1).toDate());

    /**
     * retrieve the calendars defined for this portlet instance
     */

    CalendarSet<?> set = calendarSetDao.getCalendarSet(request);
    List<CalendarConfiguration> calendars = new ArrayList<CalendarConfiguration>();
    calendars.addAll(set.getConfigurations());
    Collections.sort(calendars, new CalendarConfigurationByNameComparator());
    model.put("calendars", calendars);

    Map<Long, Integer> colors = new HashMap<Long, Integer>();
    Map<Long, String> links = new HashMap<Long, String>();
    int index = 0;
    for (CalendarConfiguration callisting : calendars) {

        // don't bother to fetch hidden calendars
        if (hiddenCalendars.get(callisting.getId()) == null) {

            try {

                // get an instance of the adapter for this calendar
                ICalendarAdapter adapter = (ICalendarAdapter) applicationContext
                        .getBean(callisting.getCalendarDefinition().getClassName());

                //get hyperlink to calendar
                String link = adapter.getLink(callisting, interval, request);
                if (link != null) {
                    links.put(callisting.getId(), link);
                }

            } catch (NoSuchBeanDefinitionException ex) {
                log.error("Calendar class instance could not be found: " + ex.getMessage());
            } catch (CalendarLinkException linkEx) {
                // Not an error. Ignore
            } catch (Exception ex) {
                log.error(ex);
            }
        }

        // add this calendar's id to the color map
        colors.put(callisting.getId(), index);
        index++;

    }

    model.put("timezone", session.getAttribute("timezone"));
    model.put("colors", colors);
    model.put("links", links);
    model.put("hiddenCalendars", hiddenCalendars);

    /*
     * Check if we need to disable either the preferences and/or administration links
     */

    Boolean disablePrefs = Boolean.valueOf(prefs.getValue(PREFERENCE_DISABLE_PREFERENCES, "false"));
    model.put(PREFERENCE_DISABLE_PREFERENCES, disablePrefs);
    Boolean disableAdmin = Boolean.valueOf(prefs.getValue(PREFERENCE_DISABLE_ADMINISTRATION, "false"));
    model.put(PREFERENCE_DISABLE_ADMINISTRATION, disableAdmin);

    return new ModelAndView(viewSelector.getCalendarViewName(request), "model", model);
}

From source file:org.n52.io.img.ChartRenderer.java

License:Open Source License

protected Date getStartTime(String timespan) {
    Interval interval = Interval.parse(timespan);
    return interval.getStart().toDate();
}

From source file:org.n52.io.img.ChartRenderer.java

License:Open Source License

protected Date getEndTime(String timespan) {
    Interval interval = Interval.parse(timespan);
    return interval.getEnd().toDate();
}

From source file:org.n52.io.IntervalWithTimeZone.java

License:Open Source License

/**
 * @param timespan the time interval in ISO8601 notation.
 * @throws IoParseException if timespan is not a valid interval.
 *//* w  ww. jav  a  2 s. c o  m*/
public IntervalWithTimeZone(String timespan) {
    try {
        Interval.parse(timespan);
        this.timespan = timespan;
    } catch (IllegalArgumentException e) {
        String message = "Could not parse timespan parameter." + timespan;
        throw new IoParseException(message, e);
    }
}

From source file:org.n52.io.IntervalWithTimeZone.java

License:Open Source License

public Interval toInterval() {
    return Interval.parse(timespan);
}

From source file:org.n52.io.IoParameters.java

License:Open Source License

private Interval validateTimespan(String timespan) {
    try {//from  w  w w  .  ja v a  2 s . co m
        return Interval.parse(timespan);
    } catch (IllegalArgumentException e) {
        String message = "Could not parse timespan parameter." + timespan;
        throw new IoParseException(message, e);
    }
}

From source file:org.n52.io.v1.data.ParameterSet.java

License:Open Source License

private String validateTimespan(String timespan) {
    return Interval.parse(timespan).toString();
}