List of usage examples for org.joda.time DateTime minusDays
public DateTime minusDays(int days)
From source file:net.sourceforge.fenixedu.presentationTier.Action.messaging.AnnouncementsStartPageHandler.java
License:Open Source License
private DateTime getStartDate(HttpServletRequest request) { final String selectedTimeSpanString = request.getParameter("recentBoardsTimeSpanSelection"); final RecentBoardsTimeSpanSelection selectedTimeSpan = (selectedTimeSpanString != null) ? RecentBoardsTimeSpanSelection.valueOf(selectedTimeSpanString) : RecentBoardsTimeSpanSelection.TS_LAST_WEEK; final DateTime now = new DateTime(); DateTime startDate = null;/*from ww w .ja va2 s . com*/ switch (selectedTimeSpan) { case TS_ALL_ACTIVE: break; case TS_LAST_WEEK: startDate = now.minusDays(7); break; case TS_ONE_MONTH: startDate = now.minusDays(30); break; case TS_TWO_MONTHS: startDate = now.minusDays(60); break; case TS_TODAY: startDate = now.minusHours(now.hourOfDay().get()); startDate = startDate.minusMinutes(now.minuteOfHour().get()); startDate = startDate.minusSeconds(now.secondOfMinute().get()); break; case TS_TWO_WEEKS: startDate = now.minusDays(15); break; case TS_YESTERDAY: startDate = now.minusDays(1); break; } return startDate; }
From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixAPICanteen.java
License:Open Source License
public static String get(String daySearch) { String locale = I18N.getLocale().toString().replace("_", "-"); if (canteenInfo == null || canteenInfo.isJsonNull() || oldInformation()) { String canteenUrl = FenixConfigurationManager.getConfiguration().getFenixApiCanteenUrl(); try {/*ww w .j a v a2s.c o m*/ Response response = HTTP_CLIENT.target(canteenUrl).request(MediaType.APPLICATION_JSON) .header("Authorization", getServiceAuth()).get(); if (response.getStatus() == 200) { JsonParser parser = new JsonParser(); canteenInfo = (JsonObject) parser.parse(response.readEntity(String.class)); day = new DateTime(); } else { return new JsonObject().toString(); } } catch (ProcessingException e) { e.printStackTrace(); return new JsonObject().toString(); } } JsonArray jsonArrayWithLang = canteenInfo.getAsJsonArray(locale); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (dateToCompare.isAfter(dayToCompareStart) && dateToCompare.isBefore(dayToCompareEnd)) { jsonResult.add(jObj); } } Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(jsonResult); }
From source file:net.tourbook.ui.views.calendar.CalendarGraph.java
License:Open Source License
private void drawWeekInfo(final GC gc, final DateTime dt, final Rectangle rec) { final Font normalFont = gc.getFont(); final FontData fd[] = normalFont.getFontData(); fd[0].setStyle(SWT.BOLD);//from ww w . j a v a2 s . com // fd[0].setHeight(((rec.height) * 72 / _display.getDPI().y) / 4); final Font boldFont = new Font(_display, fd[0]); gc.setForeground(_darkGray); gc.setBackground(_white); gc.setFont(boldFont); String text; if (_tinyLayout) { if (dt.minusDays(1).getMonthOfYear() != dt.plusDays(6).getMonthOfYear()) { // a new month started on this week gc.setClipping(new Rectangle(rec.x, rec.y, rec.width, 4 * rec.height)); // clipp to the room left of this month text = dt.plusDays(6).toString("MMM"); //$NON-NLS-1$ if (rec.width < (2 * _refTextExtent.x / 3)) { text = text.substring(0, 1); } gc.drawText(text, rec.x + 2, rec.y + 2); gc.setClipping(_nullRec); } } else { gc.drawText("" + dt.getWeekOfWeekyear(), rec.x + 4, rec.y + 2);//$NON-NLS-1$ } gc.setFont(normalFont); boldFont.dispose(); }
From source file:niche.newres.timedevents2owl.randomizer.TimedEvents2OWLRandomizer.java
public static DateTime minusRandomDays(DateTime dateTime, int minRange, int maxRange) { int randomDays = TimedEvents2OWLRandomizer.randInt(minRange, maxRange); return dateTime.minusDays(randomDays); }
From source file:org.adeptnet.auth.saml.SAMLClient.java
License:Apache License
private void validate(final Response response) throws ValidationException { if (response.getStatus() == null || response.getStatus().getStatusCode() == null || !(StatusCode.SUCCESS_URI.equals(response.getStatus().getStatusCode().getValue()))) { throw new ValidationException("Response has an unsuccessful status code"); }/*from w w w . ja v a 2 s .c om*/ // response destination must match ACS if (!config.getSPConfig().getAcs().equals(response.getDestination())) { throw new ValidationException("Response is destined for a different endpoint"); } final DateTime now = DateTime.now(); // issue instant must be within a day final DateTime issueInstant = response.getIssueInstant(); if (issueInstant != null) { if (issueInstant.isBefore(now.minusDays(1).minusSeconds(slack))) { throw new ValidationException("Response IssueInstant is in the past"); } if (issueInstant.isAfter(now.plusDays(1).plusSeconds(slack))) { throw new ValidationException("Response IssueInstant is in the future"); } } for (Assertion assertion : response.getAssertions()) { // Assertion must be signed correctly if (!assertion.isSigned()) { throw new ValidationException("Assertion must be signed"); } final Signature sig2 = assertion.getSignature(); sigValidator.validate(sig2); // Assertion must contain an authnstatement // with an unexpired session if (assertion.getAuthnStatements().isEmpty()) { throw new ValidationException("Assertion should contain an AuthnStatement"); } for (AuthnStatement as : assertion.getAuthnStatements()) { if (as.getSessionNotOnOrAfter() == null) { LOG.error("SessionNotOnOrAfter is null"); continue; } final DateTime exp = as.getSessionNotOnOrAfter().plusSeconds(slack); if (exp != null && (now.isEqual(exp) || now.isAfter(exp))) { throw new ValidationException("AuthnStatement has expired"); } } if (assertion.getConditions() == null) { throw new ValidationException("Assertion should contain conditions"); } // Assertion IssueInstant must be within a day final DateTime instant = assertion.getIssueInstant(); if (instant != null) { if (instant.isBefore(now.minusDays(1).minusSeconds(slack))) { throw new ValidationException("Response IssueInstant is in the past"); } if (instant.isAfter(now.plusDays(1).plusSeconds(slack))) { throw new ValidationException("Response IssueInstant is in the future"); } } // Conditions must be met by current time final Conditions conditions = assertion.getConditions(); DateTime notBefore = conditions.getNotBefore(); DateTime notOnOrAfter = conditions.getNotOnOrAfter(); if (notBefore == null) { notBefore = now; } if (notBefore == null || notOnOrAfter == null) { throw new ValidationException("Assertion conditions must have limits"); } notBefore = notBefore.minusSeconds(slack); notOnOrAfter = notOnOrAfter.plusSeconds(slack); if (now.isBefore(notBefore)) { throw new ValidationException("Assertion conditions is in the future"); } if (now.isEqual(notOnOrAfter) || now.isAfter(notOnOrAfter)) { throw new ValidationException("Assertion conditions is in the past"); } // If subjectConfirmationData is included, it must // have a recipient that matches ACS, with a valid // NotOnOrAfter final Subject subject = assertion.getSubject(); if (subject != null && !subject.getSubjectConfirmations().isEmpty()) { boolean foundRecipient = false; for (SubjectConfirmation sc : subject.getSubjectConfirmations()) { if (sc.getSubjectConfirmationData() == null) { continue; } final SubjectConfirmationData scd = sc.getSubjectConfirmationData(); if (scd.getNotOnOrAfter() != null) { final DateTime chkdate = scd.getNotOnOrAfter().plusSeconds(slack); if (now.isEqual(chkdate) || now.isAfter(chkdate)) { throw new ValidationException("SubjectConfirmationData is in the past"); } } if (config.getSPConfig().getAcs().equals(scd.getRecipient())) { foundRecipient = true; } } if (!foundRecipient) { throw new ValidationException("No SubjectConfirmationData found for ACS"); } } // audience must include intended SP issuer if (conditions.getAudienceRestrictions().isEmpty()) { throw new ValidationException("Assertion conditions must have audience restrictions"); } // only one audience restriction supported: we can only // check against the single SP. if (conditions.getAudienceRestrictions().size() > 1) { throw new ValidationException("Assertion contains multiple audience restrictions"); } final AudienceRestriction ar = conditions.getAudienceRestrictions().get(0); // at least one of the audiences must match our SP boolean foundSP = false; for (Audience a : ar.getAudiences()) { if (config.getSPConfig().getEntityId().equals(a.getAudienceURI())) { foundSP = true; } } if (!foundSP) { throw new ValidationException("Assertion audience does not include issuer"); } } }
From source file:org.akop.crosswords.fragment.SubscriptionDetailFragment.java
License:Open Source License
private void refreshPuzzles() { Set<DateTime> existingDates = new TreeSet<>(); for (PuzzleWrapper wrapper : mAdapter.mItems) { existingDates.add(wrapper.mPuzzle.getDate()); }//www . ja va 2 s .c om DateTime now = DateTime.now(); DateTime today = CrosswordFetchRunnable.Request.truncateDateTime(now); DateTime stopDate = today.minusDays(mSource.getBacklogInDays()); List<CrosswordFetchRunnable.Request> requests = new ArrayList<>(); while (today.isAfter(stopDate)) { if (!existingDates.contains(today)) { requests.add(new CrosswordFetchRunnable.Request(mSource, today)); } today = today.minusDays(1); } if (requests.size() > 0) { CrosswordFetchRunnable.Request[] array = new CrosswordFetchRunnable.Request[requests.size()]; requests.toArray(array); FetcherTask task = new FetcherTask(); task.execute(array); } }
From source file:org.apache.cloudstack.saml.SAMLUtils.java
License:Apache License
public static X509Certificate generateRandomX509Certificate(KeyPair keyPair) throws NoSuchAlgorithmException, NoSuchProviderException, CertificateEncodingException, SignatureException, InvalidKeyException { DateTime now = DateTime.now(DateTimeZone.UTC); X500Principal dnName = new X500Principal("CN=ApacheCloudStack"); X509V1CertificateGenerator certGen = new X509V1CertificateGenerator(); certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis())); certGen.setSubjectDN(dnName);/*from ww w .jav a2 s .c om*/ certGen.setIssuerDN(dnName); certGen.setNotBefore(now.minusDays(1).toDate()); certGen.setNotAfter(now.plusYears(3).toDate()); certGen.setPublicKey(keyPair.getPublic()); certGen.setSignatureAlgorithm("SHA256WithRSAEncryption"); return certGen.generate(keyPair.getPrivate(), "BC"); }
From source file:org.apache.cloudstack.utils.security.CertUtils.java
License:Apache License
public static X509Certificate generateV1Certificate(final KeyPair keyPair, final String subject, final String issuer, final int validityYears, final String signatureAlgorithm) throws CertificateException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, InvalidKeyException, OperatorCreationException { final DateTime now = DateTime.now(DateTimeZone.UTC); final X509v1CertificateBuilder certBuilder = new JcaX509v1CertificateBuilder(new X500Name(issuer), generateRandomBigInt(), now.minusDays(1).toDate(), now.plusYears(validityYears).toDate(), new X500Name(subject), keyPair.getPublic()); final ContentSigner signer = new JcaContentSignerBuilder(signatureAlgorithm).setProvider("BC") .build(keyPair.getPrivate()); final X509CertificateHolder certHolder = certBuilder.build(signer); return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certHolder); }
From source file:org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.DateConverterForJodaDateTime.java
License:Apache License
@Override protected DateTime doConvertToObject(String value, Locale locale) throws ConversionException { final DateTime parsedDateTime = convert(value); return parsedDateTime.minusDays(adjustBy); }
From source file:org.apache.pig.pen.AugmentBaseDataVisitor.java
License:Apache License
Object GetSmallerValue(Object v) { byte type = DataType.findType(v); if (type == DataType.BAG || type == DataType.TUPLE || type == DataType.MAP) return null; switch (type) { case DataType.CHARARRAY: String str = (String) v; if (str.length() > 0) return str.substring(0, str.length() - 1); else//from w ww .j ava2 s. c o m return null; case DataType.BYTEARRAY: DataByteArray data = (DataByteArray) v; if (data.size() > 0) return new DataByteArray(data.get(), 0, data.size() - 1); else return null; case DataType.INTEGER: return Integer.valueOf((Integer) v - 1); case DataType.LONG: return Long.valueOf((Long) v - 1); case DataType.FLOAT: return Float.valueOf((Float) v - 1); case DataType.DOUBLE: return Double.valueOf((Double) v - 1); case DataType.BIGINTEGER: return ((BigInteger) v).subtract(BigInteger.ONE); case DataType.BIGDECIMAL: return ((BigDecimal) v).subtract(BigDecimal.ONE); case DataType.DATETIME: DateTime dt = (DateTime) v; if (dt.getMillisOfSecond() != 0) { return dt.minusMillis(1); } else if (dt.getSecondOfMinute() != 0) { return dt.minusSeconds(1); } else if (dt.getMinuteOfHour() != 0) { return dt.minusMinutes(1); } else if (dt.getHourOfDay() != 0) { return dt.minusHours(1); } else { return dt.minusDays(1); } default: return null; } }