List of usage examples for org.joda.time Interval getStart
public DateTime getStart()
From source file:org.filteredpush.qc.date.DwCEventDQ.java
License:Apache License
/** * Given an eventDate check to see if that event date crosses outside a range from a * specified lower bound (1700-01-01 by default) and the present. * //from ww w .j a va2 s . c om * TODO: This may or may not be consistent with the standard test * TG2-VALIDATION_EVENTDATE_OUTOFRANGE * * * @param eventDate to check * @param lowerBound integer representing the year to use as the lower boundary, if null, then uses 1700 * @param useLowerBound if false, no lower limit, otherwise uses supplied lower bound. * @return an DQValidationResponse object describing whether the provided value is in range. */ @Provides(value = "urn:uuid:3cff4dc4-72e9-4abe-9bf3-8a30f1618432") @Validation(label = "VALIDATION_EVENTDATE_EXTENDSOUTOFRANGE", description = "The range of dwc:eventDate does not extend into the future and optionally does not extend before a date designated when the test is run") @Specification(value = "The range of dwc:eventDate does not extend into the future and optionally does not extend before a date designated when the test is run The field dwc:eventDate is not EMPTY.") public static DQResponse<ComplianceValue> isEventDateAtAllInRange( @ActedUpon(value = "dwc:eventDate") String eventDate, @Parameter(name = "extendsOutOfRangeLowerBound") Integer lowerBound, @Parameter(name = "extendsOutOfRangeUseLowerBound") Boolean useLowerBound) { DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>(); // TODO: Implementation may be too tightly bound to year, may need to extract first/last day for finer granularity test if (lowerBound == null) { lowerBound = 1700; } if (useLowerBound == null) { useLowerBound = true; } Integer upperBound = LocalDateTime.now().getYear(); if (DateUtils.isEmpty(eventDate)) { result.addComment("No value provided for dwc:eventDate."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { if (!DateUtils.eventDateValid(eventDate)) { result.addComment( "Value provided for dwc:eventDate [" + eventDate + "] not recognized as a valid date."); result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { int startYear = 0; Interval interval = DateUtils.extractInterval(eventDate); if (DateUtils.isRange(eventDate)) { int endYear = interval.getEnd().getYear(); startYear = interval.getStart().getYear(); if (endYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' extends outside the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { if (useLowerBound) { if (startYear < lowerBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' extends outside the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is a range spanning at least part of " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } } else { startYear = interval.getStart().getYear(); if (useLowerBound) { if (startYear < lowerBound || startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' does not have a year in the range " + lowerBound.toString() + " to " + upperBound.toString() + " (current year)."); } } else { if (startYear > upperBound) { result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is not after " + upperBound.toString() + " (current year)."); } else { result.setValue(ComplianceValue.COMPLIANT); result.addComment("Provided value for dwc:eventDate '" + eventDate + "' is after " + upperBound.toString() + " (current year)."); } } } result.setResultState(ResultState.RUN_HAS_RESULT); } } return result; }
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. * //ww w . j a v a 2 s . 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.gephi.desktop.timeline.TickGraph.java
License:Open Source License
private void drawDate(Graphics2D g) { int width = parameters.getWidth(); int height = parameters.getHeight(); //Font/*from ww w.j ava2 s.c o m*/ int fontSize = Math.min(parameters.getFontSize(), (int) (height / 4.)); fontSize = fontSize > parameters.getFontSize() / 4 && fontSize <= parameters.getFontSize() / 2 ? parameters.getFontSize() / 2 : fontSize; FontMetrics smallMetrics = null; Font smallFont = parameters.getFont(); Font bigFont; FontMetrics bigMetrics; if (smallFont != null && fontSize > parameters.getFontSize() / 4) { smallFont = smallFont.deriveFont(Font.PLAIN, fontSize); smallMetrics = g.getFontMetrics(smallFont); bigFont = smallFont.deriveFont(Font.PLAIN, (int) (fontSize * 2.5)); bigMetrics = g.getFontMetrics(bigFont); } else { smallFont = null; bigFont = null; } DateTick dateTick = DateTick.create(min, max, width); int TOP_TICK = 0; int LOWER_TICK = 1; //Lower tick if (dateTick.getTypeCount() > 1) { g.setFont(smallFont); g.setColor(parameters.getDateColor(LOWER_TICK)); Interval[] intervals = dateTick.getIntervals(LOWER_TICK); int labelWidth = smallMetrics != null ? smallMetrics.stringWidth("0000") : 0; for (Interval interval : intervals) { long ms = interval.getStartMillis(); int x = dateTick.getTickPixelPosition(ms, width); if (x >= 0) { g.setColor(parameters.getDateColor(LOWER_TICK)); //Height int h = (int) (Math.min(40, (int) (height / 15.0))); //Draw line g.drawLine(x, 0, x, h); //Label if (smallFont != null && width / intervals.length > labelWidth) { String label = dateTick.getTickValue(LOWER_TICK, interval.getStart()); int xLabel = x + 4; g.setColor(parameters.getDateColor(1)); int y = (int) (fontSize * 1.2); g.drawString(label, xLabel, y); } } } } //Top tick if (dateTick.getTypeCount() > 0) { g.setFont(bigFont); g.setColor(parameters.getDateColor(TOP_TICK)); Interval[] intervals = dateTick.getIntervals(TOP_TICK); for (Interval interval : intervals) { long ms = interval.getStartMillis(); int x = dateTick.getTickPixelPosition(ms, width); if (x >= 0) { g.setColor(parameters.getDateColor(TOP_TICK)); //Height int h = height; //Draw Line g.drawLine(x, 0, x, h); //Label if (bigFont != null) { String label = dateTick.getTickValue(TOP_TICK, interval.getStart()); int xLabel = x + 4; g.setColor(parameters.getDateColor(TOP_TICK)); int y = (int) (fontSize * 4); g.drawString(label, xLabel, y); } } else if (x > ((dateTick.getTickPixelPosition(interval.getEndMillis(), width) - x) / -2)) { if (bigFont != null) { String label = dateTick.getTickValue(TOP_TICK, interval.getStart()); g.setColor(parameters.getDateColor(TOP_TICK)); int y = (int) (fontSize * 4); g.drawString(label, 4, y); } } } } }
From source file:org.jadira.usertype.dateandtime.joda.PersistentInterval.java
License:Apache License
@Override protected Object[] toConvertedColumns(Interval value) { return new Object[] { value.getStart(), value.getEnd() }; }
From source file:org.jasig.cas.client.validation.Saml11TicketValidator.java
License:Apache License
private boolean isValidAssertion(final org.opensaml.saml1.core.Assertion assertion) { final DateTime notBefore = assertion.getConditions().getNotBefore(); final DateTime notOnOrAfter = assertion.getConditions().getNotOnOrAfter(); if (notBefore == null || notOnOrAfter == null) { logger.debug("Assertion has no bounding dates. Will not process."); return false; }//from w ww . ja v a 2 s. c o m final DateTime currentTime = new DateTime(DateTimeZone.UTC); final Interval validityRange = new Interval(notBefore.minus(this.tolerance), notOnOrAfter.plus(this.tolerance)); if (validityRange.contains(currentTime)) { logger.debug("Current time is within the interval validity."); return true; } if (currentTime.isBefore(validityRange.getStart())) { logger.debug("skipping assertion that's not yet valid..."); return false; } logger.debug("skipping expired assertion..."); return false; }
From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java
License:Apache License
/** * Get a JSON-appropriate representation of each recurrence of an event * within the specified time period./*from w w w.jav a 2 s . com*/ * * @param e * @param interval * @param usersConfiguredDateTimeZone * @return * @throws IOException * @throws URISyntaxException * @throws ParseException */ protected Set<CalendarDisplayEvent> getDisplayEvents(VEvent e, Interval interval, Locale locale, DateTimeZone usersConfiguredDateTimeZone) throws IOException, URISyntaxException, ParseException { final VEvent event = (VEvent) e.copy(); DateTime eventStart; DateTime eventEnd = null; if (event.getStartDate().getTimeZone() == null && !event.getStartDate().isUtc()) { if (log.isDebugEnabled()) { log.debug("Identified event " + event.getSummary() + " as a floating event"); } int offset = usersConfiguredDateTimeZone.getOffset(event.getStartDate().getDate().getTime()); eventStart = new DateTime(event.getStartDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); } } else { eventStart = new DateTime(event.getStartDate().getDate(), usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate(), usersConfiguredDateTimeZone); } } if (eventEnd == null) { eventEnd = eventStart; } // Multi-day events may begin in the past; make sure to choose a date in range for the first pass... final Date firstDayToProcess = interval.contains(event.getStartDate().getDate().getTime()) ? event.getStartDate().getDate() : interval.getStart().toDate(); DateMidnight startOfTheSpecificDay = new DateMidnight(firstDayToProcess, usersConfiguredDateTimeZone); DateMidnight endOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); final DateTimeFormatter df = getDateFormatter(locale, usersConfiguredDateTimeZone); final DateTimeFormatter tf = getTimeFormatter(locale, usersConfiguredDateTimeZone); final Set<CalendarDisplayEvent> events = new HashSet<CalendarDisplayEvent>(); final Interval eventInterval = new Interval(eventStart, eventEnd); do { final Interval theSpecificDay = new Interval(startOfTheSpecificDay.getMillis(), endOfTheSpecificDay.getMillis(), usersConfiguredDateTimeZone); /* * Test if the event interval abuts the start of the day or is within the day. * This start time check is needed for the corner case where a zero duration interval * is set for midnight. * The start times are tested directly as opposed to using abuts() because that method * also returns true if the intervals abut at the end of the day. We want to associate * instant events that start at midnight with the starting day, not the ending day. */ if (theSpecificDay.getStart().isEqual(eventStart) || theSpecificDay.overlaps(eventInterval)) { final CalendarDisplayEvent json = new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df, tf); events.add(json); } startOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); endOfTheSpecificDay = endOfTheSpecificDay.plusDays(1); } while (!startOfTheSpecificDay.isAfter(eventEnd) && interval.contains(startOfTheSpecificDay)); return events; }
From source file:org.jasig.portlet.calendar.adapter.CoursesCalendarAdapter.java
License:Apache License
public CalendarEventSet getEvents(CalendarConfiguration calendarConfiguration, Interval interval, PortletRequest request) throws CalendarException { String intervalCacheKey = cacheKeyGenerator.getKey(calendarConfiguration, interval, request, cacheKeyPrefix.concat(".") + interval.toString()); // Get the calendar event set for the set of terms from cache CalendarEventSet eventSet;//from w w w .j a v a 2 s .c o m Element cachedElement = this.cache.get(intervalCacheKey); if (cachedElement != null) { if (log.isDebugEnabled()) { log.debug("Retrieving calendar event set from cache, termCacheKey:" + intervalCacheKey); } return (CalendarEventSet) cachedElement.getValue(); } // Get the terms that overlap the requested interval. Current implementation // requires the terms to have the start date and end date present in the // term. TermList allTerms = courseDao.getTermList(request); Set<VEvent> calendarEventSet = new HashSet<VEvent>(); for (Term term : allTerms.getTerms()) { // todo determine if term ending Fri 10/31 (which means THROUGH 10/31 to 23:59:59) // and interval starting Fri 10/31 (meaning 10/31 12:00am) works as expected. // Determine if the interval overlaps any terms. if (interval.getStart().isBefore(term.getEnd().getTimeInMillis()) && interval.getEnd().isAfter(term.getStart().getTimeInMillis())) { Calendar calendar = retrieveCourseCalendar(request, interval, calendarConfiguration, term); Set<VEvent> events = contentProcessor.getEvents(interval, calendar); log.debug("contentProcessor found " + events.size() + " events"); calendarEventSet.addAll(events); } } // Save the calendar event set to the cache. eventSet = new CalendarEventSet(intervalCacheKey, calendarEventSet); cachedElement = new Element(intervalCacheKey, eventSet); if (log.isDebugEnabled()) { log.debug("Storing calendar event set to cache, key:" + intervalCacheKey); } cache.put(cachedElement); return eventSet; }
From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapter.java
License:Apache License
protected GetUserAvailabilityRequest getAvailabilityRequest(Interval interval, String emailAddress) throws DatatypeConfigurationException { // construct the SOAP request object to use GetUserAvailabilityRequest soapRequest = new GetUserAvailabilityRequest(); // create an array of mailbox data representing the current user ArrayOfMailboxData mailboxes = new ArrayOfMailboxData(); MailboxData mailbox = new MailboxData(); Mailbox address = new Mailbox(); address.setAddress(emailAddress);//from www .ja v a 2 s . com address.setName(""); mailbox.setAttendeeType(MeetingAttendeeType.REQUIRED); mailbox.setExcludeConflicts(false); mailbox.setEmail(address); mailboxes.getMailboxDatas().add(mailbox); soapRequest.setMailboxDataArray(mailboxes); // create a FreeBusyViewOptions representing the specified period FreeBusyViewOptions view = new FreeBusyViewOptions(); view.setMergedFreeBusyIntervalInMinutes(60); view.getRequestedView().add("DetailedMerged"); Duration dur = new Duration(); XMLGregorianCalendar start = getXmlDate(interval.getStart()); XMLGregorianCalendar end = getXmlDate(interval.getEnd()); dur.setEndTime(end); dur.setStartTime(start); view.setTimeWindow(dur); soapRequest.setFreeBusyViewOptions(view); // set the bias to the start time's timezone offset (in minutes // rather than milliseconds) TimeZone tz = new TimeZone(); java.util.TimeZone tZone = java.util.TimeZone.getTimeZone(UTC); tz.setBias(tZone.getRawOffset() / 1000 / 60); // TODO: time zone standard vs. daylight info is temporarily hard-coded SerializableTimeZoneTime standard = new SerializableTimeZoneTime(); standard.setBias(0); standard.setDayOfWeek(DayOfWeekType.SUNDAY); standard.setDayOrder((short) 1); standard.setMonth((short) 11); standard.setTime("02:00:00"); SerializableTimeZoneTime daylight = new SerializableTimeZoneTime(); daylight.setBias(0); daylight.setDayOfWeek(DayOfWeekType.SUNDAY); daylight.setDayOrder((short) 1); daylight.setMonth((short) 3); daylight.setTime("02:00:00"); tz.setStandardTime(standard); tz.setDaylightTime(daylight); soapRequest.setTimeZone(tz); return soapRequest; }
From source file:org.jasig.portlet.calendar.mvc.CalendarDisplayEvent.java
License:Apache License
/** * Constructs an object from specified data. * * @param event "Raw" Event object/* w w w .ja v a2 s . c o m*/ * @param eventInterval Interval portion of the event that applies to this specific day * @param theSpecificDay Interval of the specific day in question * @param df date formatter to represent date displays * @param tf time formatter to represent time displays */ public CalendarDisplayEvent(VEvent event, Interval eventInterval, Interval theSpecificDay, DateTimeFormatter df, DateTimeFormatter tf) { assert theSpecificDay.abuts(eventInterval) || theSpecificDay.overlaps(eventInterval) : "Event interval is not in the specified day!"; this.summary = event.getSummary() != null ? event.getSummary().getValue() : null; this.description = event.getDescription() != null ? event.getDescription().getValue() : null; this.location = event.getLocation() != null ? event.getLocation().getValue() : null; boolean multi = false; if (eventInterval.getStart().isBefore(theSpecificDay.getStart())) { dayStart = theSpecificDay.getStart(); multi = true; } else { dayStart = eventInterval.getStart(); } if (event.getEndDate() == null) { dayEnd = dayStart; } else if (eventInterval.getEnd().isAfter(theSpecificDay.getEnd())) { dayEnd = theSpecificDay.getEnd(); multi = true; } else { dayEnd = eventInterval.getEnd(); } this.isMultiDay = multi; this.dateStartTime = tf.print(dayStart); this.startTime = tf.print(eventInterval.getStart()); this.startDate = df.print(eventInterval.getStart()); if (event.getEndDate() != null) { this.dateEndTime = tf.print(dayEnd); this.endTime = tf.print(eventInterval.getEnd()); this.endDate = df.print(eventInterval.getEnd()); } else { this.dateEndTime = null; this.endTime = null; this.endDate = null; } Interval dayEventInterval = new Interval(dayStart, dayEnd); this.isAllDay = dayEventInterval.equals(theSpecificDay); }
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) {/* w ww .j a v a 2 s. c o m*/ 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); }