List of usage examples for org.joda.time DateTime plus
public DateTime plus(ReadablePeriod period)
From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java
License:Educational Community License
public List<TimeBlock> buildTimeBlocksSpanDates(Assignment assignment, String earnCode, TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours, BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String spanningWeeks, String userPrincipalId) { DateTimeZone zone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime beginDt = beginDateTime.withZone(zone); DateTime endDt = beginDt.toLocalDate().toDateTime(endDateTime.withZone(zone).toLocalTime(), zone); if (endDt.isBefore(beginDt)) endDt = endDt.plusDays(1);// w ww .j ava 2 s. com List<Interval> dayInt = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry()); TimeBlock firstTimeBlock = new TimeBlock(); List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>(); DateTime endOfFirstDay = null; // KPME-2568 long diffInMillis = 0; // KPME-2568 for (Interval dayIn : dayInt) { if (dayIn.contains(beginDt)) { if (dayIn.contains(endDt) || dayIn.getEnd().equals(endDt)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (dayIn.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY || dayIn.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) { // Get difference in millis for the next time block - KPME-2568 endOfFirstDay = endDt.withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } else { firstTimeBlock = createTimeBlock(timesheetDocument, beginDateTime, endDt, assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(firstTimeBlock); } } else { //TODO move this to prerule validation //throw validation error if this case met error } } } DateTime endTime = endDateTime.withZone(zone); if (firstTimeBlock.getEndDateTime() != null) { // KPME-2568 endOfFirstDay = firstTimeBlock.getEndDateTime().withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } DateTime currTime = beginDt.plusDays(1); while (currTime.isBefore(endTime) || currTime.isEqual(endTime)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (currTime.getDayOfWeek() == DateTimeConstants.SATURDAY || currTime.getDayOfWeek() == DateTimeConstants.SUNDAY)) { // do nothing } else { TimeBlock tb = createTimeBlock(timesheetDocument, currTime, currTime.plus(diffInMillis), assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(tb); } currTime = currTime.plusDays(1); } return lstTimeBlocks; }
From source file:org.marketcetera.core.time.TimeFactoryImpl.java
@Override public DateTime create(String inValue) { inValue = StringUtils.trimToNull(inValue); Validate.notNull(inValue);/*from w ww . java 2s . c o m*/ DateTime value = null; for (DateTimeFormatter formatter : FORMATTERS) { try { value = formatter.parseDateTime(inValue); } catch (IllegalArgumentException ignored) { } } if (value != null && SECONDS_PATTERN.matcher(inValue).matches()) { value = value.plus(new LocalDate().toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis()); } Validate.notNull(value); return value; }
From source file:org.mrgeo.geometry.splitter.TimeSpanGeometrySplitter.java
License:Apache License
@Override public void initialize(Map<String, String> splitterProperties, final boolean uuidOutputNames, final String[] outputNames) { String timeFormat = splitterProperties.get(TIME_FORMAT_PROPERTY); if (timeFormat == null || timeFormat.isEmpty()) { dtf = ISODateTimeFormat.dateTime(); } else {/*from www .ja v a2s .com*/ dtf = DateTimeFormat.forPattern(timeFormat); } DateTime startTime = getTimeProperty(splitterProperties, START_TIME_PROPERTY, dtf); DateTime endTime = getTimeProperty(splitterProperties, END_TIME_PROPERTY, dtf); String strInterval = splitterProperties.get(INTERVAL_PROPERTY); if (strInterval == null || strInterval.isEmpty()) { throw new IllegalArgumentException("Missing interval property for time span geometry splitter"); } int seconds = -1; try { seconds = Integer.parseInt(strInterval); } catch (NumberFormatException nfe) { throw new IllegalArgumentException( "Invalid value for interval property for time span geometry splitter"); } Period interval = Period.seconds(seconds); startField = splitterProperties.get(START_FIELD_PROPERTY); if (startField == null || startField.isEmpty()) { throw new IllegalArgumentException("Missing startField property for time span geometry splitter"); } endField = splitterProperties.get(END_FIELD_PROPERTY); if (endField == null || endField.isEmpty()) { throw new IllegalArgumentException("Missing endField property for time span geometry splitter"); } compareType = TimeSpanGeometrySplitter.CompareType.END_TIME; String strCompareType = splitterProperties.get(COMPARE_TYPE_PROPERTY); if (strCompareType != null && !strCompareType.isEmpty()) { compareType = compareTypeFromString(strCompareType); } List<DateTime> breakpointsList = new ArrayList<DateTime>(); DateTime currBreakpoint = startTime; while (currBreakpoint.compareTo(endTime) <= 0) { breakpointsList.add(currBreakpoint); currBreakpoint = currBreakpoint.plus(interval); } // If the endTime is greater than the last breakpoint, then // include one more breakpoint. if (endTime.compareTo(currBreakpoint.minus(interval)) > 0) { breakpointsList.add(currBreakpoint); } if ((outputNames != null) && (breakpointsList.size() != outputNames.length)) { throw new IllegalArgumentException( "Invalid set of output names specified for the time span" + " geometry splitter. There are " + breakpointsList.size() + " breakpoints, and " + outputNames.length + " output names"); } breakpoints = new DateTime[breakpointsList.size()]; breakpointsList.toArray(breakpoints); outputs = new String[breakpoints.length]; for (int i = 0; i < breakpoints.length; i++) { String output; if (outputNames != null) { output = outputNames[i]; } else { if (uuidOutputNames) { output = UUID.randomUUID().toString(); } else { output = breakpoints[i].toString(dtf); // DirectoryMultipleOutputs only allows alphanumeric characters output = output.replaceAll("[^\\p{Alnum}]", ""); } } outputs[i] = output; } }
From source file:org.mythtv.android.utils.DateUtils.java
License:Open Source License
public static DateTime getDaysFromToday(int days) { DateTime day = convertUtc(new DateTime(DateTimeZone.UTC)); day = day.plus(Period.days(days)); return getEndOfDay(day); }
From source file:org.mythtv.android.utils.DateUtils.java
License:Open Source License
public static DateTime getNextDay(DateTime day) { day = day.plus(Period.days(1)); return getEndOfDay(day); }
From source file:org.mythtv.android.utils.DateUtils.java
License:Open Source License
public static DateTime getNextDayAfterMythfilldatabase() { DateTime day = convertUtc(new DateTime(DateTimeZone.UTC)); day = day.plus(Period.days(1)); return day.withTime(4, 0, 0, 0); }
From source file:org.openhab.binding.sonos.internal.SonosZonePlayer.java
License:Open Source License
public boolean setAlarm(boolean alarmSwitch) { List<SonosAlarm> sonosAlarms = getCurrentAlarmList(); if (isConfigured()) { // find the nearest alarm - take the current time from the Sonos System, not the system where openhab is // running String currentLocalTime = getTime(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime currentDateTime = fmt.parseDateTime(currentLocalTime); Duration shortestDuration = Period.days(10).toStandardDuration(); SonosAlarm firstAlarm = null;//ww w . j a va2s. c om for (SonosAlarm anAlarm : sonosAlarms) { Duration duration = new Duration(currentDateTime, anAlarm.getStartTime()); if (anAlarm.getStartTime().isBefore(currentDateTime.plus(shortestDuration)) && anAlarm.getRoomUUID().equals(udn.getIdentifierString())) { shortestDuration = duration; firstAlarm = anAlarm; } } // Set the Alarm if (firstAlarm != null) { if (alarmSwitch) { firstAlarm.setEnabled(true); } else { firstAlarm.setEnabled(false); } return updateAlarm(firstAlarm); } else { return false; } } else { return false; } }
From source file:org.openmrs.module.reporting.dataset.definition.evaluator.RepeatPerTimePeriodDataSetEvaluator.java
License:Open Source License
@Override public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext evalContext) throws EvaluationException { RepeatPerTimePeriodDataSetDefinition dsd = (RepeatPerTimePeriodDataSetDefinition) dataSetDefinition; Mapped<? extends DataSetDefinition> baseMappedDef = dsd.getBaseDefinition(); MultiParameterDataSetDefinition delegate = new MultiParameterDataSetDefinition( baseMappedDef.getParameterizable()); TimePeriod period = dsd.getRepeatPerTimePeriod(); if (period == null) { throw new IllegalArgumentException("repeatPerTimePeriod is required"); }// w w w . java2 s. c o m DateTime thisPeriodStart = new DateTime(((Date) evalContext.getParameterValue("startDate")).getTime()); DateTime end = new DateTime( DateUtil.getEndOfDayIfTimeExcluded((Date) evalContext.getParameterValue("endDate")).getTime()); while (thisPeriodStart.isBefore(end)) { DateTime nextPeriodStart = thisPeriodStart.plus(period.getJodaPeriod()); boolean lastIteration = !nextPeriodStart.isBefore(end); // i.e. nextPeriodStart >= end DateTime thisPeriodEnd; if (lastIteration) { thisPeriodEnd = end; } else { thisPeriodEnd = nextPeriodStart.minus(Duration.millis(1)); } Map<String, Object> startAndEndDate = new HashMap<String, Object>(); startAndEndDate.put("startDate", thisPeriodStart.toDate()); startAndEndDate.put("endDate", thisPeriodEnd.toDate()); Map<String, Object> iteration = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : baseMappedDef.getParameterMappings().entrySet()) { String iterationParamName = entry.getKey(); Object value = entry.getValue(); if (value instanceof String) { Object evaluated = EvaluationUtil.evaluateExpression((String) value, startAndEndDate); // expressions based on parameters other than startDate/endDate will come out like ${loc} -> "loc" if (value.equals(EvaluationUtil.EXPRESSION_START + evaluated + EvaluationUtil.EXPRESSION_END)) { continue; } value = evaluated; } iteration.put(iterationParamName, value); } delegate.addIteration(iteration); thisPeriodStart = nextPeriodStart; } return dataSetDefinitionService.evaluate(delegate, evalContext); }
From source file:org.opensaml.saml.common.binding.security.impl.MessageLifetimeSecurityHandler.java
License:Open Source License
/** {@inheritDoc} */ @Override//from ww w .j ava 2 s . c o m public void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException { final SAMLMessageInfoContext msgInfoContext = messageContext.getSubcontext(SAMLMessageInfoContext.class, true); if (msgInfoContext.getMessageIssueInstant() == null) { if (requiredRule) { log.warn("{} Inbound SAML message issue instant not present in message context", getLogPrefix()); throw new MessageHandlerException( "Inbound SAML message issue instant not present in message context"); } else { return; } } final DateTime issueInstant = msgInfoContext.getMessageIssueInstant(); final DateTime now = new DateTime(); final DateTime latestValid = now.plus(getClockSkew()); final DateTime expiration = issueInstant.plus(getClockSkew() + getMessageLifetime()); // Check message wasn't issued in the future if (issueInstant.isAfter(latestValid)) { log.warn("{} Message was not yet valid: message time was {}, latest valid is: {}", getLogPrefix(), issueInstant, latestValid); throw new MessageHandlerException("Message was rejected because was issued in the future"); } // Check message has not expired if (expiration.isBefore(now)) { log.warn( "{} Message was expired: message issue time was '{}', message expired at: '{}', current time: '{}'", getLogPrefix(), issueInstant, expiration, now); throw new MessageHandlerException("Message was rejected due to issue instant expiration"); } }
From source file:org.opensaml.saml.metadata.resolver.impl.AbstractDynamicMetadataResolver.java
License:Open Source License
/** * Compute the effective expiration time for the specified metadata. * /*w w w.ja va 2 s . c om*/ * @param entityDescriptor the EntityDescriptor instance to evaluate * @param now the current date time instant * @return the effective expiration time for the metadata */ @Nonnull protected DateTime computeExpirationTime(@Nonnull final EntityDescriptor entityDescriptor, @Nonnull final DateTime now) { DateTime lowerBound = now.toDateTime(ISOChronology.getInstanceUTC()).plus(getMinCacheDuration()); DateTime expiration = SAML2Support.getEarliestExpiration(entityDescriptor, now.plus(getMaxCacheDuration()), now); if (expiration.isBefore(lowerBound)) { expiration = lowerBound; } return expiration; }