List of usage examples for org.joda.time DateTime plusMinutes
public DateTime plusMinutes(int minutes)
From source file:org.n52.iceland.util.DateTimeHelper.java
License:Open Source License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime/* w w w.j a va 2 s.com*/ * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(final DateTime dateTime, final int isoTimeLength) { switch (isoTimeLength) { // year case YEAR: return dateTime.plusYears(ONE_VALUE).minusMillis(ONE_VALUE); // year, month case YEAR_MONTH: return dateTime.plusMonths(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day case YEAR_MONTH_DAY: return dateTime.plusDays(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute, second case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(ONE_VALUE).minusMillis(ONE_VALUE); default: return dateTime; } }
From source file:org.n52.iceland.util.DateTimeHelper.java
License:Open Source License
/** * Calculates the expire time for a time object * * @param start/* w ww.j ava2s. c o m*/ * Time object * @return Expire time */ public static DateTime calculateExpiresDateTime(final DateTime start) { return start.plusMinutes(lease); }
From source file:org.n52.shetland.util.DateTimeHelper.java
License:Apache License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime/* ww w. j a v a 2s .co m*/ * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(DateTime dateTime, int isoTimeLength) { switch (isoTimeLength) { case YEAR: return dateTime.plusYears(1).minusMillis(1); case YEAR_MONTH: return dateTime.plusMonths(1).minusMillis(1); case YEAR_MONTH_DAY: return dateTime.plusDays(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(1).minusMillis(1); default: return dateTime; } }
From source file:org.n52.shetland.util.DateTimeHelper.java
License:Apache License
/** * Calculates the expire time for a time object * * @param start/*from w ww.ja v a 2s . com*/ * Time object * @return Expire time */ public static DateTime calculateExpiresDateTime(DateTime start) { return start.plusMinutes(lease); }
From source file:org.n52.sos.SosDateTimeUtilities.java
License:Open Source License
/** * calculates the expires DateTime of the observationCollection from the start DateTime of the request and the * lease property of the config file/*from ww w . ja v a 2s . c o m*/ * * @param start * start DateTime for the lease * @return Returns the expires DateTime */ public static DateTime calculateExpiresDateTime(DateTime start) { DateTime end = null; end = start.plusMinutes(lease); return end; }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsExpression(DateTime origin, String duration) { int k = getFactor(duration); switch (duration.substring(duration.length() - 1, duration.length())) { case "s": return origin.plusSeconds(k); case "m": return origin.plusMinutes(k); case "h": return origin.plusHours(k); case "d": return origin.plusDays(k); case "w": return origin.plusWeeks(k); case "M": return origin.plusMonths(k); case "y": return origin.plusYears(k); }//w w w . j ava2s.c om return invalid(duration); }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsNoun(DateTime origin, String duration) { switch (duration.toLowerCase()) { case "second": return origin.plusSeconds(1); case "minute": return origin.plusMinutes(1); case "hour": return origin.plusHours(1); case "day": return origin.plusDays(1); case "week": return origin.plusWeeks(1); case "month": return origin.plusMonths(1); case "quarter": return origin.plusMonths(3); case "year": return origin.plusYears(1); }//from ww w. ja v a2 s. c o m return invalid(duration); }
From source file:org.ojbc.util.camel.security.saml.GFIPM_SAML2ComponentBuilder.java
License:RPL License
/** * Create a Conditions object//from w w w . j a va 2 s. c o m * * @param entityIDfromAppliesToAddress a string to create an appliesTo element from * @param delegateNameID a string to create a new delegate element from * @param existingTokenConditions existing delegates to preserve * @return a Conditions object */ @SuppressWarnings("unchecked") public static Conditions createConditions(String entityIDfromAppliesToAddress, String delegateNameID, Conditions existingTokenConditions) throws Exception { if (conditionsBuilder == null) { conditionsBuilder = (SAMLObjectBuilder<Conditions>) builderFactory .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); } //Within the <Conditions> element of the assertion, add a new <Delegate> element. //Within the new <Delegate> element, add a <NameID> element with a value equal to the SAML 2.0 Metadata Entity ID that appears in the GFIPM CTF //for the WSC that requested the assertion.58,59 //Also, on the new <Delegate> element, add a 'DelegationInstant' attribute containing a timestamp representing the current moment in time. //Assertion/Conditions //Modify the 'NotBefore' attribute of the <Conditions> element to contain a timestamp representing the current moment in time. DateTime notBefore = new DateTime(); log.debug("Not before time: " + notBefore.toString("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); //Modify the 'NotOnOrAfter' attribute of the <Conditions> element to contain a timestamp representing a moment in time that is N seconds in the future, //where N represents length of time, in seconds, for which the new assertion will be valid. DateTime notOnOrAfter = notBefore.plusMinutes(5); log.debug("Not On or After time: " + notOnOrAfter.toString("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); Conditions conditions = conditionsBuilder.buildObject(); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); if (!StringUtils.isEmpty(entityIDfromAppliesToAddress)) { AudienceRestriction audienceRestriction = GFIPM_SAML2ComponentBuilder .createAudienceRestriction(entityIDfromAppliesToAddress); conditions.getAudienceRestrictions().add(audienceRestriction); } //It is possible, through a chain of SAML assertion delegations, for multiple <Delegate> elements to appear inside a <Conditions> element. //When adding a new <Delegate> element, the ADS MUST NOT delete or modify any previously existing <Delegate> elements that already appear in the assertion. DelegationRestrictionType existingDelegateConditions = null; //Only one delegate condition is allowed, find and detach //http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-delegation-cs-01.html //A SAML authority MUST NOT include more than one <saml:Condition> element of this type within a <saml:Conditions> element of an assertion. if (existingTokenConditions != null) { for (Condition condition : existingTokenConditions.getConditions()) { String conditionSchema = condition.getSchemaType().getNamespaceURI(); log.debug("Condition schema type: " + condition.getSchemaType().getNamespaceURI()); if (conditionSchema.equals("urn:oasis:names:tc:SAML:2.0:conditions:delegation")) { existingDelegateConditions = (DelegationRestrictionType) condition; break; } } } List<Delegate> existingDelegates = null; if (existingDelegateConditions != null) { existingDelegates = existingDelegateConditions.getDelegates(); } if (!StringUtils.isEmpty(delegateNameID)) { DelegationRestrictionType delegateRestrictions = createDelegateRestriction(delegateNameID, existingDelegates); conditions.getConditions().add(delegateRestrictions); } return conditions; }
From source file:org.openhab.binding.imperihab.internal.imperiHabBinding.java
License:Open Source License
private String generateHistoryData(String requestUrl) { String[] parts = requestUrl.substring(1).split("/"); String deviceId = parts[1];// ww w.j a v a 2 s. c o m String paramKey = parts[2]; Date start = new Date(Long.parseLong(parts[4])); Date end = new Date(Long.parseLong(parts[5])); log("deviceId: " + deviceId + ", paramKey: " + paramKey + ", start: " + start + ", end:" + end); Item item = null; try { item = itemRegistry.getItem(deviceId); } catch (ItemNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String persistService = getPersistService(item.getName()); ArrayList<String> data = new ArrayList<String>(); if (item != null) { DateTime date = new DateTime(start.getTime()); while (date.isAfter(end.getTime()) == false) { HistoricItem histItem; if (persistService == null) histItem = PersistenceExtensions.historicState(item, date); else histItem = PersistenceExtensions.historicState(item, date, persistService); if (histItem != null) data.add( "{\"value\":" + histItem.getState().toString() + ",\"date\":" + date.getMillis() + "}"); date = date.plusMinutes(30); } } return "{\"values\":[" + imperiHabUtils.join(data, ",") + "]}"; }
From source file:org.openhab.persistence.caldav.internal.CaldavPersistenceService.java
License:Open Source License
@Override public void store(Item item, String alias) { if (item.getState() instanceof UnDefType) { return;// w w w. j a va 2 s . c o m } DateTime dateOffset = DateTime.now().plusDays(futureOffset); if (alias == null) { alias = item.getName(); } State state = item.getState(); logger.trace("persisting item: {}", item); if (!singleEvents) { // try to create events with correct ON OFF duration final CaldavItem lastOn = this.findLastOn(alias, state); if (lastOn != null) { if (isOff(item.getState())) { CalDavEvent event = lastOn.getEvent(); event.setLastChanged(DateTime.now()); String offContent = EventUtils.createEnd(alias, state); event.setContent(event.getContent() + "\n" + offContent); event.setEnd(dateOffset); logger.debug("existing event found, updated for persistence: {}", event); this.calDavLoader.addEvent(event); } else { CalDavEvent event = lastOn.getEvent(); event.setLastChanged(dateOffset); String offContent = EventUtils.createBetween(alias, state); event.setContent(event.getContent() + "\n" + offContent); logger.debug("existing event found, updated for persistence: {}", event); this.calDavLoader.addEvent(event); } return; } } logger.debug("creating new event"); CalDavEvent event = new CalDavEvent(); final String id = UUID.randomUUID().toString(); event.setId(id); event.setName(alias); event.setLastChanged(DateTime.now()); event.setContent(EventUtils.createBegin(alias, state)); event.setStart(dateOffset); event.setEnd(dateOffset.plusMinutes(duration)); event.setCalendarId(calendarId); event.setFilename("openHAB-" + id); logger.debug("new event for persistence created: {}", event); this.calDavLoader.addEvent(event); }