List of usage examples for java.time.temporal ChronoUnit DAYS
ChronoUnit DAYS
To view the source code for java.time.temporal ChronoUnit DAYS.
Click Source Link
From source file:io.manasobi.utils.DateUtils.java
public static int getDays(LocalDateTime startDateTime, LocalDateTime endDateTime) { return (int) ChronoUnit.DAYS.between(startDateTime, endDateTime); }
From source file:org.bedework.synch.cnctrs.orgSyncV2.OrgSyncV2ConnectorInstance.java
@Override public URI getUri() throws SynchException { try {//from w w w . j a v a 2s .co m //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()) .setParameter("key", cnctr.getSyncher().decrypt(info.getPassword())) .setParameter("start_date", yesterdayStr).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepositoryTest.java
@Test public void updateSubscriptionTest() throws URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext);//from w w w .j a v a2s.c o m subscriptionsRepository.saveSubscription(subscription); Map<String, Subscription> subscriptions = subscriptionsRepository.getAllSubscriptions(); Assert.assertEquals(1, subscriptions.size()); Assert.assertEquals("P1M", subscriptions.get("12345").getSubscribeContext().getDuration()); subscribeContext.setDuration("PT1D"); subscription.setExpirationDate(Instant.now().plus(1, ChronoUnit.DAYS)); subscriptionsRepository.updateSubscription(subscription); subscriptions = subscriptionsRepository.getAllSubscriptions(); Assert.assertEquals(1, subscriptions.size()); Assert.assertEquals("PT1D", subscriptions.get("12345").getSubscribeContext().getDuration()); Assert.assertEquals(subscription.getExpirationDate(), subscriptions.get("12345").getExpirationDate()); }
From source file:org.thevortex.lighting.jinks.robot.Recurrence.java
/** * Get the next occurrence from a time./*w w w . j a v a 2s. c o m*/ * * @param fromWhen when * @return the next occurrence or {@code null} if there is no more */ public LocalDateTime nextOccurrence(TemporalAccessor fromWhen) { LocalDateTime from = LocalDateTime.from(fromWhen); // if it's not today, try the next day if (frequency == Frequency.WEEKLY && !days.contains(from.getDayOfWeek())) { return nextOccurrence(from.plusDays(1).truncatedTo(ChronoUnit.DAYS)); } // if we've already started, it's too late - next day if (from.toLocalTime().isAfter(startTime)) { return nextOccurrence(from.plusDays(1).truncatedTo(ChronoUnit.DAYS)); } // otherwise, we're on the right day, so just adjust the time return from.with(startTime).truncatedTo(ChronoUnit.MINUTES); }
From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java
/** * ??/*from w w w . j a va 2 s.c o m*/ * * @param map * @return */ public List<UserArticle> getTopReadArticlesByCategoryIdAndTime(Map<String, Object> map) { List<UserArticle> userArticles = userArticleService.getTopReadArticles(map); List<UserArticle> articles = userArticleService .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) { //??DEFAULT_DAYS_BEFORE_PLUS map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME)) .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS))); userArticles = this.getTopReadArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:com.diversityarrays.kdxplore.stats.DateSimpleStatistics.java
public DateSimpleStatistics(String statsName, List<KdxSample> samples, Integer nStdDevForOutlier) { super(statsName, Date.class); nSampleMeasurements = samples.size(); Bag<String> bag = new HashBag<>(); List<Long> values = new ArrayList<>(nSampleMeasurements); for (KdxSample sm : samples) { switch (TraitValue.classify(sm.getTraitValue())) { case NA://w w w . ja v a 2s. co m ++nNA; break; case SET: try { Date date = dateFormat.parse(sm.getTraitValue()); long millis = date.getTime(); values.add(millis); bag.add(String.valueOf(millis)); } catch (ParseException e) { ++nInvalid; } break; case MISSING: case UNSET: default: ++nMissing; break; } } nValidValues = values.size(); switch (nValidValues) { case 0: minValue = null; maxValue = null; mode = null; median = null; mean = null; variance = null; stddev = null; nOutliers = null; stderr = null; break; case 1: mean = new Date(values.get(0)); median = mean; minValue = mean; maxValue = mean; mode = dateFormat.format(mean); variance = null; stddev = null; nOutliers = null; stderr = null; break; default: Collections.sort(values); minValue = new Date(values.get(0)); maxValue = new Date(values.get(values.size() - 1)); mean = new Date((minValue.getTime() + maxValue.getTime()) / 2); long median_l = StatsUtil.computeLongMedian(values); median = new Date(median_l); List<String> modes = StatsUtil.computeMode(bag, null); StringBuilder sb = new StringBuilder(); String sep = ""; for (String s : modes) { sb.append(sep); long millis = Long.parseLong(s); Date d = new Date(millis); sb.append(dateFormat.format(d)); sep = " , "; } mode = sb.toString(); // - - - - // Now for variance, stddev, stderr, nOutliers Instant start = minValue.toInstant(); long meanDays = ChronoUnit.DAYS.between(start, mean.toInstant()); double s2 = 0; for (Long v : values) { s2 += (v - meanDays) * (v - meanDays); } variance = s2 / (nValidValues - 1); stddev = Math.sqrt(variance); stderr = stddev / Math.sqrt(nValidValues); double q1 = BoxAndWhiskerCalculator.calculateQ1(values); double q3 = BoxAndWhiskerCalculator.calculateQ3(values); int nout = 0; if (nStdDevForOutlier == null) { double interQuartileRange = q3 - q1; double lowerOutlierThreshold = q1 - (interQuartileRange * 1.5); double upperOutlierThreshold = q3 + (interQuartileRange * 1.5); for (Long value : values) { if (value < lowerOutlierThreshold) { ++nout; lowOutliers.add(new Date(value)); } else if (value > upperOutlierThreshold) { ++nout; highOutliers.add(new Date(value)); } if (lowerOutlierThreshold < value || value < upperOutlierThreshold) { ++nout; } } } else { double lowerOutlierThreshold = meanDays - (nStdDevForOutlier * stddev); double upperOutlierThreshold = meanDays + (nStdDevForOutlier * stddev); for (Long v : values) { Date d = new Date(v); long nDays = ChronoUnit.DAYS.between(start, d.toInstant()); if (nDays < lowerOutlierThreshold) { ++nout; lowOutliers.add(d); } else if (nDays > upperOutlierThreshold) { ++nout; highOutliers.add(d); } } } nOutliers = nout; break; } }
From source file:devbury.dewey.plugins.RemindMe.java
private Date notifyAt(long amount, String units) { ChronoUnit chronoUnit = ChronoUnit.SECONDS; switch (units) { case "weeks": case "week": chronoUnit = ChronoUnit.WEEKS; break;/* w w w . j a v a2 s .c o m*/ case "months": case "month": chronoUnit = ChronoUnit.MONTHS; break; case "days": case "day": chronoUnit = ChronoUnit.DAYS; break; case "hours": case "hour": chronoUnit = ChronoUnit.HOURS; break; case "minutes": case "minute": chronoUnit = ChronoUnit.MINUTES; break; } return Date.from(Instant.now().plus(amount, chronoUnit)); }
From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java
/** * ??//from w ww . j ava2 s.c o m * * @param map * @return */ private List<UserArticle> getTopReadArticlesByCategoryIdAndTime(Map<String, Object> map) { List<UserArticle> userArticles = userArticleMapper.getTopReadArticles(map); List<UserArticle> articles = userArticleMapper .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) { //??DEFAULT_DAYS_BEFORE_PLUS map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME)) .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS))); userArticles = this.getTopReadArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:com.orange.cepheus.broker.LocalRegistrationsTest.java
@Test public void testUpdateRegistration() throws Exception { RegisterContext registerContext = createRegistrationContext(); registerContext.setRegistrationId("12345"); Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext); reset(registrationsRepository);/* w ww . j a va 2 s. co m*/ when(registrationsRepository.getRegistration(any())).thenReturn(registration); String registrationId = localRegistrations.updateRegistrationContext(registerContext); Assert.hasLength(registrationId); assertNotEquals("12345", registrationId); Registration registration2 = localRegistrations.getRegistration(registrationId); assertNotNull(registration2); assertNotNull(registration2.getExpirationDate()); verify(remoteRegistrations).registerContext(eq(registerContext), eq(registrationId)); verify(registrationsRepository).getRegistration(eq(registrationId)); verify(registrationsRepository).updateRegistration(eq(registration)); }
From source file:alfio.model.modification.EventWithStatistics.java
public boolean isExpired() { return ZonedDateTime.now(event.getZoneId()).truncatedTo(ChronoUnit.DAYS) .isAfter(event.getEnd().truncatedTo(ChronoUnit.DAYS)); }