List of usage examples for java.time.temporal ChronoUnit MINUTES
ChronoUnit MINUTES
To view the source code for java.time.temporal ChronoUnit MINUTES.
Click Source Link
From source file:org.jhk.pulsing.web.service.prod.PulseService.java
/** * Hmmm should work in DRPC from storm+trident to get notified of new batch and then send * the message to client component for new set? Look into it since familiar only w/ trident * // w w w. java 2 s .c om * @param numMinutes * @return */ @Override public Map<Long, String> getTrendingPulseSubscriptions(int numMinutes) { Instant current = Instant.now(); Instant beforeRange = current.minus(numMinutes, ChronoUnit.MINUTES); Optional<Set<String>> optTps = redisPulseDao.getTrendingPulseSubscriptions(beforeRange.getEpochSecond(), current.getEpochSecond()); @SuppressWarnings("unchecked") Map<Long, String> tpSubscriptions = Collections.EMPTY_MAP; if (optTps.isPresent()) { tpSubscriptions = PulseServiceUtil.processTrendingPulseSubscribe(optTps.get(), _objectMapper); } ; return tpSubscriptions; }
From source file:ru.jts_dev.gameserver.time.GameTimeService.java
public long minutesPassedSinceDayBeginning() { final ZonedDateTime dayBeginning = dateTime.with(LocalTime.MIN); return dayBeginning.until(dateTime, ChronoUnit.MINUTES); }
From source file:org.jimsey.project.turbine.spring.controller.TickControllerTest.java
@Test public void testGetAllTicksGreaterThanDate() throws Exception { // use this for a spy... // Mockito.doReturn(123l).when(ping).ping(); // String result = // "{\"date\":1437757461193,\"open\":93.31372449905724,\"high\":94.64656138818943,\"low\":92.35919077806433,\"close\":94.08436014274173,\"volume\":97.2503072332036,\"symbol\":\"ABC\",\"market\":\"FTSE100\",\"timestamp\":\"2015-07-24T18:04:21.193+01:00\"}, // {\"date\":1437757457169,\"open\":95.76421881828955,\"high\":98.67332820497525,\"low\":92.87399277681914,\"close\":95.30416761402581,\"volume\":96.25382742497295,\"symbol\":\"ABC\",\"market\":\"FTSE100\",\"timestamp\":\"2015-07-24T18:04:17.169+01:00\"}, // {\"date\":1437757455156,\"open\":95.20691875293008,\"high\":96.33109747791707,\"low\":95.03864535693057,\"close\":95.76421881828955,\"volume\":104.54628090784864,\"symbol\":\"ABC\",\"market\":\"FTSE100\",\"timestamp\":\"2015-07-24T18:04:15.156+01:00\"}, // {\"date\":1437757459179,\"open\":95.30416761402581,\"high\":95.88765706158829,\"low\":92.37627010410178,\"close\":93.31372449905724,\"volume\":92.83201741698048,\"symbol\":\"ABC\",\"market\":\"FTSE100\",\"timestamp\":\"2015-07-24T18:04:19.179+01:00\"}"; Mockito.when(elasticsearch.findTicksByMarketAndSymbolAndDateGreaterThan(Mockito.anyString(), Mockito.anyString(), Mockito.any(Long.class))).thenReturn(ticks); String expected = json.writeValueAsString(new Object() { @JsonProperty("ticks") List<TickJson> tickz = ticks; });//from w w w. j ava 2 s . c om long date = Instant.now().minus(1, ChronoUnit.MINUTES).toEpochMilli(); String restUri = String.format("%s/any/any/%s", TurbineCondenserConstants.REST_ROOT_TICKS, date); mvc.perform(MockMvcRequestBuilders.get(restUri).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(content().string(equalTo(expected))); }
From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java
/** Returns the suffix of a time-based index given the grouping period * @param grouping_period - the grouping period * @param lowest_granularity// w ww. j a v a 2 s . c o m * @return the index suffix, ie added to the base index */ public static String getTimeBasedSuffix(final ChronoUnit grouping_period, final Optional<ChronoUnit> lowest_granularity) { return lowest_granularity .map(lg -> grouping_period.compareTo(lg) < 0 ? getTimeBasedSuffix(lg, Optional.empty()) : null) .orElse(Patterns.match(grouping_period).<String>andReturn() .when(p -> ChronoUnit.SECONDS == p, __ -> "yyyy.MM.dd.HH:mm:ss") .when(p -> ChronoUnit.MINUTES == p, __ -> "yyyy.MM.dd.HH:mm") .when(p -> ChronoUnit.HOURS == p, __ -> "yyyy.MM.dd.HH") .when(p -> ChronoUnit.DAYS == p, __ -> "yyyy.MM.dd") .when(p -> ChronoUnit.WEEKS == p, __ -> "YYYY-ww") // (deliberately 'Y' (week-year) not 'y' since 'w' is week-of-year .when(p -> ChronoUnit.MONTHS == p, __ -> "yyyy.MM") .when(p -> ChronoUnit.YEARS == p, __ -> "yyyy").otherwise(__ -> "")); }
From source file:org.thevortex.lighting.jinks.robot.Recurrence.java
/** * @return the ICAL-formatted string//from ww w . j ava 2s . c o m */ @Override public String toString() { StringBuilder formatted = new StringBuilder(DTSTART) .append(ZonedDateTime.now().with(startTime).truncatedTo(ChronoUnit.MINUTES).format(ICAL_DT)); // if we have a duration, there's an end if (duration != null) { formatted.append('\n').append(DTEND).append(ZonedDateTime.now().with(startTime.plus(duration)) .truncatedTo(ChronoUnit.MINUTES).format(ICAL_DT)); } // always a frequency formatted.append('\n').append(RRULE).append(FREQ).append(frequency); if (frequency == Frequency.WEEKLY) { // build the buffer of days StringBuilder dayBuilder = new StringBuilder(); boolean notFirst = false; DayOfWeek lastDay = null; for (DayOfWeek day : days) { if (notFirst) { dayBuilder.append(','); } notFirst = true; dayBuilder.append(day.name().substring(0, 2)); lastDay = day; } String formattedDays = dayBuilder.toString(); // if SUNDAY is at the end, move it to the front if (lastDay == DayOfWeek.SUNDAY) { formattedDays = "SU," + formattedDays.substring(0, formattedDays.lastIndexOf(",")); } // spit it out formatted.append(';').append(BYDAY).append(formattedDays); } return formatted.toString(); }
From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java
/** Low level util because java8 time "plus" is odd * @param to_adjust//from w ww . j a va 2 s. c o m * @param increment * @return */ private static Date adjustTime(Date to_adjust, ChronoUnit increment) { return Patterns.match(increment).<Date>andReturn() .when(t -> t == ChronoUnit.SECONDS, __ -> DateUtils.addSeconds(to_adjust, 1)) .when(t -> t == ChronoUnit.MINUTES, __ -> DateUtils.addMinutes(to_adjust, 1)) .when(t -> t == ChronoUnit.HOURS, __ -> DateUtils.addHours(to_adjust, 1)) .when(t -> t == ChronoUnit.DAYS, __ -> DateUtils.addDays(to_adjust, 1)) .when(t -> t == ChronoUnit.WEEKS, __ -> DateUtils.addWeeks(to_adjust, 1)) .when(t -> t == ChronoUnit.MONTHS, __ -> DateUtils.addMonths(to_adjust, 1)) .when(t -> t == ChronoUnit.YEARS, __ -> DateUtils.addYears(to_adjust, 1)).otherwiseAssert(); }
From source file:com.amazonaws.sample.entitlement.authorization.CognitoIdentityAuthorizationHandler.java
/** * @param authorization//from w w w .j av a 2 s . c o m * An authorization string. The first part of the string must match one of the keys in AUTHORIZATION_TYPES * The remainder of the string must be an OAuth2 or OpenId access token. * @return an Identity containing the IdentityID from Amazon Cognito, and email, and name from the third-party * @throws AuthorizationException */ @Override public Identity processAuthorization(String authorization) throws AuthorizationException { String authorizationType; Identity thirdPartyIdentity; String trimmedAuthorization = authorization.trim(); try { String[] splitString = trimmedAuthorization.split("\\s"); authorizationType = splitString[0]; } catch (Exception e) { throw new AuthorizationException("Don't know how to handle authorization."); } if (!AUTHORIZATION_TYPES.containsKey(authorizationType)) { throw new AuthorizationException("Don't know how to handle authorization type: " + authorizationType); } Util.checkAuthorizationString(authorizationType, authorization); // Verify that the access token is valid and belongs to us. // If the access token can be verified and also profile information can be retrieved with one call to the oauth2 // provider then return an Identity object here, otherwise return null and a separate call will be made // in getIdentity to retrieve the profile information and create an Identity object. switch (authorizationType) { case "FacebookOAuth2": thirdPartyIdentity = facebookAuthorizationHandler.processAuthorization(authorization); log.info("Email from Facebook: " + thirdPartyIdentity.getEmail()); break; case "GoogleOAuth2": thirdPartyIdentity = googleAuthorizationHandler.processAuthorization(authorization); break; case "AmazonOAuth2": thirdPartyIdentity = loginWithAmazonAuthorizationHandler.processAuthorization(authorization); log.info("Email from Amazon: " + thirdPartyIdentity.getEmail()); break; default: throw new AuthorizationException("Don't know how to handle authorization."); } try { Instant fifteenMinutesFromNow = Instant.now().plus(15, ChronoUnit.MINUTES); String base64EncEmail = Base64.getEncoder().withoutPadding() .encodeToString(thirdPartyIdentity.getEmail().getBytes("utf-8")); GetOpenIdTokenForDeveloperIdentityRequest req = new GetOpenIdTokenForDeveloperIdentityRequest(); req.setIdentityPoolId(awsCognitoIdentityPool); req.addLoginsEntry(awsCognitoDeveloperProviderName, base64EncEmail); GetOpenIdTokenForDeveloperIdentityResult res = cognitoIdentityClient .getOpenIdTokenForDeveloperIdentity(req); thirdPartyIdentity.setId(res.getIdentityId()); thirdPartyIdentity.setToken(res.getToken()); thirdPartyIdentity.setExpires(fifteenMinutesFromNow.toEpochMilli()); } catch (UnsupportedEncodingException e) { throw new AuthorizationException("Don't know how to handle authorization."); } return thirdPartyIdentity; }
From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java
/** * Calculate the date range using the specified rule. For example: * * <ul>//from www . j av a2 s. com * <li>sinceRule=2y - 2 years</li> * <li>sinceRule=5m - 5 months</li> * <li>sinceRule=10d - 10 days</li> * <li>sinceRule=5h - 5 hours</li> * <li>sinceRule=33 - 33 minutes</li> * </ul> * * The method will result in a {@link java.util.Map Map} containing the following keys: * * <ul> * <li><b>fromDate</b> - the starting date * <li><b>toDate</b> - the ending date, which will be the current system date (i.e. now()) * </ul> * * @param sinceRule The rule to calculate the date range * * @return A {@link java.util.Map Map} */ public static final Map<String, LocalDateTime> calculateDateRange(String sinceRule) { if (StringUtils.isBlank(sinceRule)) { return ImmutableMap.of(); } final String timeDesignation = StringUtils.right(sinceRule, 1); long timeDelta = 0; try { // Assume last character is NOT a letter (i.e. all characters are digits). timeDelta = Long.parseLong(sinceRule); } catch (NumberFormatException exception) { // If an exception, then last character MUST have been a letter, // so we now exclude the last character and re-try conversion. try { timeDelta = Long.parseLong(sinceRule.substring(0, sinceRule.length() - 1)); } catch (NumberFormatException error) { log.warn("Failed to convert {} to a timeDelta/timeDesignation!", sinceRule); timeDelta = 0; } } if (timeDelta < 1) { return ImmutableMap.of(); } final LocalDateTime toDate = LocalDateTime.now(); final LocalDateTime fromDate; if (timeDesignation.equalsIgnoreCase("y")) { fromDate = toDate.minusYears(timeDelta); } else if (timeDesignation.equalsIgnoreCase("m")) { fromDate = toDate.minusMonths(timeDelta); } else if (timeDesignation.equalsIgnoreCase("d")) { fromDate = toDate.minusDays(timeDelta); } else if (timeDesignation.equalsIgnoreCase("h")) { fromDate = toDate.minus(timeDelta, ChronoUnit.HOURS); } else { fromDate = toDate.minus(timeDelta, ChronoUnit.MINUTES); } final ImmutableMap<String, LocalDateTime> dateRange = ImmutableMap.of(FROM_DATE, fromDate, TO_DATE, toDate); return dateRange; }
From source file:com.onyxscheduler.domain.SchedulerIT.java
private Instant buildNonReachableFutureDate() { return Instant.now().plus(NON_REACHABLE_FUTURE_MINUTES, ChronoUnit.MINUTES); }
From source file:org.tightblog.service.WeblogEntryManager.java
public void saveWeblogEntry(WeblogEntry entry) { if (entry.getCategory() == null) { // Entry is invalid without category, so use first one found if not provided WeblogCategory cat = entry.getWeblog().getWeblogCategories().iterator().next(); entry.setCategory(cat);//from w w w . jav a 2s .c o m } if (entry.getAnchor() == null || entry.getAnchor().trim().equals("")) { entry.setAnchor(this.createAnchor(entry)); } // if the entry was published to future, set status as SCHEDULED // we only consider an entry future published if it is scheduled // more than 1 minute into the future if (WeblogEntry.PubStatus.PUBLISHED.equals(entry.getStatus()) && entry.getPubTime().isAfter(Instant.now().plus(1, ChronoUnit.MINUTES))) { entry.setStatus(WeblogEntry.PubStatus.SCHEDULED); } // Store value object (creates new or updates existing) Instant now = Instant.now(); entry.setUpdateTime(now); weblogEntryRepository.save(entry); weblogManager.saveWeblog(entry.getWeblog(), true); }