List of usage examples for org.joda.time DateTime minusYears
public DateTime minusYears(int years)
From source file:org.springframework.analytics.rest.controller.AggregateCounterController.java
License:Apache License
/** * Return a default value for the interval start if none has been provided. *///from w w w . j a v a 2 s. c om private DateTime providedOrDefaultFromValue(DateTime from, DateTime to, AggregateCounterResolution resolution) { if (from != null) { return from; } switch (resolution) { case minute: return to.minusMinutes(59); case hour: return to.minusHours(23); case day: return to.minusDays(6); case month: return to.minusMonths(11); case year: return to.minusYears(4); default: throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } }
From source file:org.springframework.xd.dirt.rest.metrics.AggregateCountersController.java
License:Apache License
/** * Return a default value for the interval start if none has been provided. */// w w w . j a va 2s . c o m private DateTime providedOrDefaultFromValue(DateTime from, DateTime to, AggregateCountResolution resolution) { if (from != null) { return from; } switch (resolution) { case minute: return to.minusMinutes(59); case hour: return to.minusHours(23); case day: return to.minusDays(6); case month: return to.minusMonths(11); case year: return to.minusYears(4); default: throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } }
From source file:org.zgis.wps.swat.WeatherFetchAlgorithm.java
License:Apache License
private static String getObservations(String sosUrl, String sensor, String observedProperty, int years) throws IOException { String result = null;// w w w .j a v a 2s . c om String offering = null; // "SOE_GWL_MASL"; String procedure = sensor; // String observedProperty = // "http://vocab.smart-project.info/sensorweb/phenomenon/Humidity"; String responseFormat = "http://www.opengis.net/om/2.0"; // "http://www.opengis.net/waterml/2.0"; // String temporalFilter = // "om:phenomenonTime,2014-02-17T12:00:00/2014-02-18T20:00:00"; DateTimeFormatter fmt = DateTimeFormat.forPattern(" yyyy-MM-dd'T'HH:mm:ss"); DateTimeFormatter fmtTz = DateTimeFormat.forPattern(" yyyy-MM-dd'T'HH:mm:ssZZ"); DateTimeFormatter fmtIso = ISODateTimeFormat.dateTime(); DateTime now = DateTime.parse("2016-01-01 00:00:00"); DateTime minusYears = now.minusYears(years); String temporalFilter = "om:phenomenonTime," + minusYears.toString(fmtIso) + "/" + now.toString(fmtIso); StringBuilder resultList = new StringBuilder(); StringBuilder kvpRequestParams = new StringBuilder(); kvpRequestParams.append("?service=" + "SOS"); kvpRequestParams.append("&version=" + "2.0.0"); kvpRequestParams.append("&request=" + "GetObservation"); if (procedure != null && !procedure.isEmpty()) { kvpRequestParams.append("&procedure=" + URLEncoder.encode(procedure, "UTF-8")); } if (observedProperty != null && !observedProperty.isEmpty()) { kvpRequestParams.append("&observedProperty=" + URLEncoder.encode(observedProperty, "UTF-8")); } if (responseFormat != null && !responseFormat.isEmpty()) { kvpRequestParams.append("&responseFormat=" + URLEncoder.encode(responseFormat, "UTF-8")); } // om:phenomenonTime,2010-01-01T12:00:00/2011-07-01T14:00:00 if (temporalFilter != null && !temporalFilter.isEmpty()) { kvpRequestParams.append("&temporalFilter=" + URLEncoder.encode(temporalFilter, "UTF-8")); } // set the connection timeout value to xx milliseconds final HttpParams httpParams = new BasicHttpParams(); HttpClient httpclient = new DefaultHttpClient(httpParams); HttpGet httpget = new HttpGet(sosUrl + kvpRequestParams.toString()); HttpResponse response; HttpEntity entity; response = httpclient.execute(httpget); HttpEntity resEntity = response.getEntity(); BufferedReader rd = new BufferedReader(new InputStreamReader(resEntity.getContent())); String line; while ((line = rd.readLine()) != null) { resultList.append(line); } final String responseBody = resultList.toString(); OM2MeasParse read = new OM2MeasParse(); List<ObservationModel> tvps = read.readData(responseBody); httpclient.getConnectionManager().shutdown(); Collections.sort(tvps, new Comparator<ObservationModel>() { public int compare(ObservationModel m1, ObservationModel m2) { return m1.getDatetime().compareTo(m2.getDatetime()); } }); if (tvps.size() > 0) { return "OK - [" + sensor + "] last: " + tvps.get(tvps.size() - 1).getDate(); } else { return "MISSING"; } }
From source file:ph.fingra.statisticsweb.common.util.DateTimeUtil.java
License:Apache License
public static String[] getDashboardFromToWithPrev(String numType) { int num = Integer.parseInt(numType.substring(0, numType.length() - 1)); String type = numType.substring(numType.length() - 1).toLowerCase(); final DateTime now = DateTime.now(); final DateTime to = now.minusDays(1); final DateTime from = type.equals("w") ? to.minusDays(num * 7 - 1) : (type.equals("m") ? to.minusMonths(num) : to.withMonthOfYear(1).withDayOfMonth(1)); final DateTime prevTo = type.equals("y") ? to.minusYears(1) : from.minusDays(1); final DateTime prevFrom = type.equals("w") ? prevTo.minusDays(num * 7 - 1) : (type.equals("m") ? prevTo.minusMonths(num) : prevTo.withMonthOfYear(1).withDayOfMonth(1)); final DateTime yesterday = now.minusDays(1); final DateTime beforeYesterday = now.minusDays(2); String nowTime = ""; String prevTime = ""; // before or after 10 minutes if (now.getMinuteOfHour() < 10) { // before 10 minutes String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp; String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); } else { // after 10 minutes nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay()) : String.valueOf(now.getHourOfDay()); String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); }/*from www . j ava 2s.co m*/ return new String[] { from.toString("yyyy-MM-dd"), to.toString("yyyy-MM-dd"), prevFrom.toString("yyyy-MM-dd"), prevTo.toString("yyyy-MM-dd"), yesterday.toString("yyyy-MM-dd"), beforeYesterday.toString("yyyy-MM-dd"), now.toString("yyyy-MM-dd"), nowTime, prevTime }; }
From source file:se.vgregion.webbisar.tool.WebbisGenerator.java
License:Open Source License
private BirthTime getBirthTime() { DateTime now = new DateTime(); DateTime oneYearBack = now.minusYears(1); int secondsInYear = (int) ((now.getMillis() - oneYearBack.getMillis()) / 1000L); int randomSecond = rand.nextInt(secondsInYear); DateTime bd = new DateTime(oneYearBack.getMillis() + randomSecond * 1000L); return new BirthTime(bd.toDate()); }
From source file:test.integ.be.fedict.performance.CAConfiguration.java
License:Open Source License
private X509Certificate generateCertificate(PublicKey publicKey, String issuerName, PrivateKey issuerPrivateKey, X509Certificate issuerCertificate, long maxRevokedSn) throws Exception { DateTime now = new DateTime(); DateTime notBefore = now.minusYears(10); DateTime notAfter = now.plusYears(10); return TestUtils.generateCertificate(publicKey, name, issuerPrivateKey, issuerCertificate, notBefore, notAfter, "SHA512WithRSAEncryption", true, true, false, OcspServlet.getPath(issuerName), CrlServlet.getPath(issuerName), new KeyUsage(KeyUsage.cRLSign), new BigInteger(Long.toString(maxRevokedSn + 1))); }
From source file:TVShowTimelineMaker.timeConstraints.AgeConstraint.java
@Override public boolean complexApplyConstraint() { boolean changed = this.applyConstraint(); OnceDayEvent birthDay = this.mCharacter.getBirthday(); if ((!birthDay.isMarkedForComplexEval()) && this.mAtEvent.isMarkedForComplexEval()) { birthDay.setUpForComplexEval();/* w ww . j a v a 2 s . c om*/ } if (birthDay.isMarkedForComplexEval() && (!this.mAtEvent.isMarkedForComplexEval())) { this.mAtEvent.setUpForComplexEval(); } if (birthDay.isMarkedForComplexEval() && this.mAtEvent.isMarkedForComplexEval()) { NavigableSet<DateTime> birthDayDates = birthDay.getPossibleDays(); NavigableSet<DateTime> EventAtDates = this.mAtEvent.getPossibleDays(); DateTime lowerBoundOnBirthDay = EventAtDates.first().minusYears(this.upperBound).withHourOfDay(1); DateTime upperBoundOnBirthDay = EventAtDates.first().minusYears(this.lowerBound).withHourOfDay(23); Iterator<DateTime> birthDayIterator = birthDayDates.iterator(); Iterator<DateTime> EventAtDatesIterator = EventAtDates.iterator(); DateTime curBirthDay = birthDayIterator.next(); DateTime curEventAtDate = EventAtDatesIterator.next(); boolean cont = true; //while (birthDayIterator.hasNext()) { while (cont) { if (curBirthDay.isBefore(lowerBoundOnBirthDay)) { birthDayIterator.remove(); if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } changed = true; } else if (curBirthDay.isAfter(upperBoundOnBirthDay)) { if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); lowerBoundOnBirthDay = curEventAtDate.minusYears(this.upperBound).withHourOfDay(1); upperBoundOnBirthDay = curEventAtDate.minusYears(this.lowerBound).withHourOfDay(23); } else { birthDayIterator.remove(); if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } changed = true; } } else { if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); } else { cont = false; } } } birthDayIterator = birthDayDates.iterator(); EventAtDatesIterator = EventAtDates.iterator(); curBirthDay = birthDayIterator.next(); curEventAtDate = EventAtDatesIterator.next(); cont = true; DateTime lowerBoundOnEvent = birthDayDates.first().plusYears(this.lowerBound).withHourOfDay(1); DateTime upperBoundOnEvent = birthDayDates.first().plusYears(this.upperBound).withHourOfDay(23); while (cont) { if (curEventAtDate.isBefore(lowerBoundOnEvent)) { EventAtDatesIterator.remove(); if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } changed = true; } else if (curEventAtDate.isAfter(upperBoundOnEvent)) { if (birthDayIterator.hasNext()) { curBirthDay = birthDayIterator.next(); lowerBoundOnEvent = curBirthDay.plusYears(this.lowerBound).withHourOfDay(1); upperBoundOnEvent = curBirthDay.plusYears(this.upperBound).withHourOfDay(23); } else { EventAtDatesIterator.remove(); if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } changed = true; } } else { if (EventAtDatesIterator.hasNext()) { curEventAtDate = EventAtDatesIterator.next(); } else { cont = false; } } } } return changed; }
From source file:TVShowTimelineMaker.timeConstraints.AgeConstraint.java
public boolean consistentWithConstraint(DateTime inFirstDay, DateTime inSecondDay) { DateTime lowerBoundOnBirthDay = inSecondDay.minusYears(this.upperBound).withHourOfDay(1); DateTime upperBoundOnBirthDay = inSecondDay.minusYears(this.lowerBound).withHourOfDay(23); DateTime lowerBoundOnEvent = inFirstDay.plusYears(this.lowerBound).withHourOfDay(1); DateTime upperBoundOnEvent = inFirstDay.plusYears(this.upperBound).withHourOfDay(23); return !inFirstDay.isBefore(lowerBoundOnBirthDay) && !inFirstDay.isAfter(upperBoundOnBirthDay) && !inSecondDay.isBefore(lowerBoundOnEvent) && !inSecondDay.isAfter(upperBoundOnEvent); }
From source file:TVShowTimelineMaker.timeConstraints.AgeConstraint.java
@Override public Event[] increaseWhat(Placement inValues[]) { DateTime inFirstStartTime;//from www .jav a 2 s. c o m DateTime inFirstEndTime; DateTime inSecondStartTime; DateTime inSecondEndTime; if (this.mCharacter.getBirthday() instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inValues[0]; inFirstStartTime = curOnceDayEventPlacement.day; inFirstEndTime = curOnceDayEventPlacement.day; } else { OncePeriodEvent.OncePeriodEventPlacement curOncePeriodEventPlacement = (OncePeriodEvent.OncePeriodEventPlacement) inValues[0]; inFirstStartTime = curOncePeriodEventPlacement.startDay; inFirstEndTime = curOncePeriodEventPlacement.endDay; } if (this.mAtEvent instanceof OnceDayEvent) { OnceDayEvent.OnceDayEventPlacement curOnceDayEventPlacement = (OnceDayEvent.OnceDayEventPlacement) inValues[1]; inSecondStartTime = curOnceDayEventPlacement.day; inSecondEndTime = curOnceDayEventPlacement.day; } else { OncePeriodEvent.OncePeriodEventPlacement curOncePeriodEventPlacement = (OncePeriodEvent.OncePeriodEventPlacement) inValues[1]; inSecondStartTime = curOncePeriodEventPlacement.startDay; inSecondEndTime = curOncePeriodEventPlacement.endDay; } DateTime lowerBoundOnBirthDay = inSecondStartTime.minusYears(this.upperBound).withHourOfDay(1); DateTime upperBoundOnBirthDay = inSecondStartTime.minusYears(this.lowerBound).withHourOfDay(23); DateTime lowerBoundOnEvent = inFirstEndTime.plusYears(this.lowerBound).withHourOfDay(1); DateTime upperBoundOnEvent = inFirstEndTime.plusYears(this.upperBound).withHourOfDay(23); if (inFirstEndTime.isBefore(lowerBoundOnBirthDay) || inSecondStartTime.isAfter(upperBoundOnEvent)) { return new Event[] { this.mCharacter.getBirthday() }; } if (inFirstEndTime.isAfter(upperBoundOnBirthDay) || inSecondStartTime.isBefore(lowerBoundOnEvent)) { return new Event[] { this.mAtEvent }; } return new Event[] {}; }
From source file:TVShowTimelineMaker.timeConstraints.AgeGroupConstraint.java
public boolean consistentWithConstraint(DateTime inFirstDay, DateTime inSecondDay) { DateTime lowerBoundOnBirthDay = inSecondDay.minusYears(this.mAgeGroup.upperBound).withHourOfDay(1); DateTime upperBoundOnBirthDay = inSecondDay.minusYears(this.mAgeGroup.lowerBound).withHourOfDay(23); DateTime lowerBoundOnEvent = inFirstDay.plusYears(this.mAgeGroup.lowerBound).withHourOfDay(1); DateTime upperBoundOnEvent = inFirstDay.plusYears(this.mAgeGroup.upperBound).withHourOfDay(23); return !inFirstDay.isBefore(lowerBoundOnBirthDay) && !inFirstDay.isAfter(upperBoundOnBirthDay) && !inSecondDay.isBefore(lowerBoundOnEvent) && !inSecondDay.isAfter(upperBoundOnEvent); }