List of usage examples for org.joda.time DateTime toLocalTime
public LocalTime toLocalTime()
LocalTime
with the same time and chronology. From source file:net.solarnetwork.util.JodaDateFormatEditor.java
License:Open Source License
@Override public void setAsText(String text) throws IllegalArgumentException { IllegalArgumentException iae = null; // try patterns one at a time, if all fail to parse then throw exception for (DateTimeFormatter df : this.dateFormatters) { try {//w w w . j a v a 2s . c o m DateTime dt = df.parseDateTime(text); Object val = dt; switch (this.parseMode) { case LocalDate: val = dt.toLocalDate(); break; case LocalTime: val = dt.toLocalTime(); break; default: // leave as DateTime } setValue(val); iae = null; break; } catch (IllegalArgumentException e) { iae = e; } } if (iae != null) { throw iae; } }
From source file:nl.welteninstituut.tel.la.importers.ImportTask.java
License:Open Source License
/** * Checks if the specified time is allowed according to the configuration * settings.// w w w. ja v a 2s. c o m * * @param dateTime * the date time * @return true, if is time allowed */ protected boolean isTimeAllowed(final DateTime dateTime) { if (useWorkingDays && dateTime.dayOfWeek().get() > 5) { return false; } LocalTime time = dateTime.toLocalTime(); if (starttime != null && time.isBefore(starttime)) { return false; } if (endtime != null && time.isAfter(endtime)) { return false; } return true; }
From source file:org.apereo.portal.events.aggr.action.JpaSearchRequestAggregationDao.java
License:Apache License
@Override public final List<SearchRequestAggregationImpl> getAggregations(DateTime start, DateTime end, AggregationInterval interval, AggregatedGroupMapping aggregatedGroupMapping, AggregatedGroupMapping... aggregatedGroupMappings) { if (!start.isBefore(end)) { throw new IllegalArgumentException("Start must be before End: " + start + " - " + end); }// ww w. ja v a 2 s. c o m final LocalDate startDate = start.toLocalDate(); final LocalDate endDate = end.toLocalDate(); final TypedQuery<SearchRequestAggregationImpl> query = this .createQuery(this.findAllSearchRequestAggregationsByDateRangeQuery); query.setParameter(this.startDate, startDate); query.setParameter(this.startTime, start.toLocalTime()); query.setParameter(this.endDate, endDate); query.setParameter(this.endTime, end.toLocalTime()); query.setParameter(this.endPlusOneDate, endDate.plusDays(1)); query.setParameter(this.intervalParameter, interval); final Set<AggregatedGroupMapping> groups = ImmutableSet.<AggregatedGroupMapping>builder() .add(aggregatedGroupMapping).add(aggregatedGroupMappings).build(); query.setParameter(this.aggregatedGroupsParameter, groups); return query.getResultList(); }
From source file:org.apereo.portal.events.aggr.AggregationIntervalHelperImpl.java
License:Apache License
@Override public AggregationIntervalInfo getIntervalInfo(AggregationInterval interval, DateTime date) { //Chop off everything below the minutes (seconds, millis) final DateTime instant = date.minuteOfHour().roundFloorCopy(); final DateTime start, end; switch (interval) { case CALENDAR_QUARTER: { final List<QuarterDetail> quartersDetails = this.eventAggregationManagementDao.getQuartersDetails(); final QuarterDetail quarterDetail = EventDateTimeUtils.findDateRangeSorted(instant, quartersDetails); start = quarterDetail.getStartDateMidnight(date).toDateTime(); end = quarterDetail.getEndDateMidnight(date).toDateTime(); break;/*from w w w.j a va 2 s .c o m*/ } case ACADEMIC_TERM: { final List<AcademicTermDetail> academicTermDetails = this.eventAggregationManagementDao .getAcademicTermDetails(); final AcademicTermDetail academicTermDetail = EventDateTimeUtils.findDateRangeSorted(date, academicTermDetails); if (academicTermDetail == null) { return null; } start = academicTermDetail.getStart().toDateTime(); end = academicTermDetail.getEnd().toDateTime(); break; } default: { start = interval.determineStart(instant); end = interval.determineEnd(start); } } final LocalTime startTime = start.toLocalTime(); final TimeDimension startTimeDimension = this.timeDimensionDao.getTimeDimensionByTime(startTime); final DateMidnight startDateMidnight = start.toDateMidnight(); final DateDimension startDateDimension = this.dateDimensionDao.getDateDimensionByDate(startDateMidnight); return new AggregationIntervalInfo(interval, start, end, startDateDimension, startTimeDimension); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDao.java
License:Apache License
@Override public final List<T> getAggregations(DateTime start, DateTime end, Set<K> keys, AggregatedGroupMapping... aggregatedGroupMappings) { if (!start.isBefore(end)) { throw new IllegalArgumentException("Start must be before End: " + start + " - " + end); }//from ww w . j a v a2 s . co m final LocalDate startDate = start.toLocalDate(); final LocalDate endDate = end.toLocalDate(); final TypedQuery<T> query = this.createQuery(findAggregationsByDateRangeQuery); query.setParameter(this.startDate, startDate); query.setParameter(this.startTime, start.toLocalTime()); query.setParameter(this.endDate, endDate); query.setParameter(this.endTime, end.toLocalTime()); query.setParameter(this.endPlusOneDate, endDate.plusDays(1)); // Get the first key to use for the interval K key = keys.iterator().next(); query.setParameter(this.intervalParameter, key.getInterval()); this.bindAggregationSpecificKeyParameters(query, keys); final Set<AggregatedGroupMapping> groups = collectAllGroupsFromParams(keys, aggregatedGroupMappings); query.setParameter(this.aggregatedGroupsParameter, groups); return query.getResultList(); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDao.java
License:Apache License
@Override public Collection<T> getUnclosedAggregations(DateTime start, DateTime end, AggregationInterval interval) { if (!start.isBefore(end)) { throw new IllegalArgumentException("Start must be before End: " + start + " - " + end); }//from w ww .j a v a2s . c o m final LocalDate startDate = start.toLocalDate(); final LocalDate endDate = end.toLocalDate(); final TypedQuery<T> query = this.createQuery(findUnclosedAggregationsByDateRangeQuery); query.setParameter(this.startDate, startDate); query.setParameter(this.startTime, start.toLocalTime()); query.setParameter(this.endDate, endDate); query.setParameter(this.endTime, end.toLocalTime()); query.setParameter(this.endPlusOneDate, endDate.plusDays(1)); query.setParameter(this.intervalParameter, interval); //Need set to handle duplicate results from join return new LinkedHashSet<T>(query.getResultList()); }
From source file:org.apereo.portal.events.aggr.portletlayout.JpaPortletLayoutAggregationDao.java
License:Apache License
public final List<PortletLayoutAggregationImpl> getAggregationsForAllPortlets(DateTime start, DateTime end, AggregationInterval interval, AggregatedGroupMapping aggregatedGroupMapping, AggregatedGroupMapping... aggregatedGroupMappings) { if (!start.isBefore(end)) { throw new IllegalArgumentException("Start must be before End: " + start + " - " + end); }//from ww w . j ava 2s. c o m final LocalDate startDate = start.toLocalDate(); final LocalDate endDate = end.toLocalDate(); final TypedQuery<PortletLayoutAggregationImpl> query = this .createQuery(this.findAllPortletAggregationsByDateRangeQuery); query.setParameter(this.startDate, startDate); query.setParameter(this.startTime, start.toLocalTime()); query.setParameter(this.endDate, endDate); query.setParameter(this.endTime, end.toLocalTime()); query.setParameter(this.endPlusOneDate, endDate.plusDays(1)); query.setParameter(this.intervalParameter, interval); final Set<AggregatedGroupMapping> groups = ImmutableSet.<AggregatedGroupMapping>builder() .add(aggregatedGroupMapping).add(aggregatedGroupMappings).build(); query.setParameter(this.aggregatedGroupsParameter, groups); return query.getResultList(); }
From source file:org.artifactory.security.exceptions.LoginDisabledException.java
License:Open Source License
/** * Formats next login//from www . jav a 2 s .com * * @param retryAt login available from * @param showNextLogin if next login time should be shown * * @return formatted string */ private static String calcNextLogin(long retryAt, boolean showNextLogin) { DateTime delay = new DateTime(retryAt); DateTime now = DateTime.now(); long diff = delay.getMillis() - now.getMillis(); if (showNextLogin) { if (diff < SECONDS_IN_MINUTE) { long seconds = diff / ONE_SECOND; return String.format("%d seconds (%s)", seconds == 0 ? 1 : seconds, dateTimeFormatter.print(delay.toLocalTime())); } else { return String.format("%.1f minutes (%s)", diff / SECONDS_IN_MINUTE, dateTimeFormatter.print(delay.toLocalTime())); } } else { if (diff < SECONDS_IN_MINUTE) { long seconds = diff / ONE_SECOND; return String.format("%d seconds", seconds == 0 ? 1 : seconds); } else { return String.format("%.1f minutes", diff / SECONDS_IN_MINUTE); } } }
From source file:org.bensteele.jirrigate.Irrigator.java
License:Open Source License
/** * Returns the time and date the next irrigation is due based on the watering_days and * watering_start_time. It does not take into account whether or not any of the {@link Controller} * are active.// ww w . j a v a2s. c o m * * @return The time and date of the next irrigation for any controller under this irrigator's * control. */ protected DateTime nextIrrigationAt() { DateTime dt = new DateTime(); for (int i = 0; i < 7; i++) { for (final int dayOfWeek : wateringDays) { if (dayOfWeek == (dt.getDayOfWeek())) { // If it's the first run then we may match the same day we are currently on, in this case // we need to check that we don't report a time in the past. Validate that the hour and // minute right now are not past the scheduled watering time. If it's not the first run // then it's ok to let through. if (i != 0 || (i == 0 && dt.toLocalTime().isBefore(wateringStartTime))) { // Reset the hour to 0 and increment until we match the watering hour. dt = dt.withHourOfDay(0); while (dt.getHourOfDay() < wateringStartTime.getHourOfDay()) { dt = dt.plusHours(1); } // Reset the minute to 0 and increment until we match the watering minute. dt = dt.withMinuteOfHour(0); while (dt.getMinuteOfHour() < wateringStartTime.getMinuteOfHour()) { dt = dt.plusMinutes(1); } return dt; } } } dt = dt.plusDays(1); } return null; }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimeColumnLocalTimeMapper.java
License:Apache License
@Override public LocalTime fromNonNullValue(Time value) { DateTime dateTime = new DateTime(value.getTime()); LocalTime localTime = dateTime.toLocalTime(); return localTime; }