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:Main.java
public static void main(String[] args) { LocalDate ld1 = LocalDate.of(2014, Month.JANUARY, 7); LocalDate ld2 = LocalDate.of(2014, Month.MAY, 18); LocalTime lt1 = LocalTime.of(7, 0); LocalTime lt2 = LocalTime.of(9, 30); long days = ld1.until(ld2, ChronoUnit.DAYS); System.out.println(days);// w ww.j a va 2 s .com long hours = lt1.until(lt2, ChronoUnit.HOURS); System.out.println(hours); long minutes = lt1.until(lt2, ChronoUnit.MINUTES); System.out.println(minutes); }
From source file:Main.java
public static ChronoUnit convert(TimeUnit tu) { if (tu == null) { return null; }/*www. ja va 2 s .c om*/ switch (tu) { case DAYS: return ChronoUnit.DAYS; case HOURS: return ChronoUnit.HOURS; case MINUTES: return ChronoUnit.MINUTES; case SECONDS: return ChronoUnit.SECONDS; case MICROSECONDS: return ChronoUnit.MICROS; case MILLISECONDS: return ChronoUnit.MILLIS; case NANOSECONDS: return ChronoUnit.NANOS; default: assert false : "there are no other TimeUnit ordinal values"; return null; } }
From source file:devbury.dewey.core.web.Main.java
@RequestMapping("/") public String index(Model model) { model.addAttribute("minutes", ChronoUnit.MINUTES.between(startTime, Instant.now())); return "core/index"; }
From source file:com.przemo.projectmanagementweb.services.TimeLogService.java
public Duration getTimeLoggedForTask(int taskId) { List<Double> t = HibernateUtil.runQuery("select sum(tl.time) from TimeLog tl where tl.task=" + taskId); if (t != null && !t.isEmpty() && t.get(0) != null) { return Duration.of((int) ((t.get(0)) * 60), ChronoUnit.MINUTES); } else {// w ww. j a v a2 s. c o m return Duration.ZERO; } }
From source file:metrolink.MetrolinkCalculator.java
public long getNextArrivalTime(List<StopTime> stopTimes, String time) { LocalTime[] timeArray = new LocalTime[stopTimes.size()]; for (int i = 0; i < stopTimes.size(); i++) { timeArray[i] = convertTime(stopTimes.get(i).getArrivalTime()); }/*from www .j av a 2 s .c om*/ Arrays.sort(timeArray); LocalTime convertedTime = convertTime(time); LocalTime timeResult = null; for (LocalTime currentTime : timeArray) { // System.out.println( currentTime ); if (currentTime.compareTo(convertedTime) >= 0) { timeResult = currentTime; break; } } if (timeResult == null) { timeResult = timeArray[0]; } long difference = convertedTime.until(timeResult, ChronoUnit.MINUTES); if (difference < 0) { difference += ONEDAYINMINUTES; } return difference; }
From source file:org.janusgraph.diskstorage.configuration.CommonConfigTest.java
@Test public void testDateParsing() { BaseConfiguration base = new BaseConfiguration(); CommonsConfiguration config = new CommonsConfiguration(base); for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) { base.setProperty("test", "100 " + unit.toString()); Duration d = config.get("test", Duration.class); assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos()); }//from ww w . jav a 2 s . c o m Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d"); for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) { base.setProperty("test", "100 " + entry.getValue()); Duration d = config.get("test", Duration.class); assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos()); } }
From source file:io.gravitee.management.service.impl.InstanceServiceImpl.java
@Override public Collection<InstanceListItem> findInstances(boolean includeStopped) { Set<EventEntity> events; if (includeStopped) { events = eventService.findByType(instancesAllState); } else {/* w w w . ja va2 s . com*/ events = eventService.findByType(instancesRunningOnly); } Instant nowMinusXMinutes = Instant.now().minus(5, ChronoUnit.MINUTES); return events.stream().map(event -> { Map<String, String> props = event.getProperties(); InstanceListItem instance = new InstanceListItem(props.get("id")); instance.setEvent(event.getId()); instance.setLastHeartbeatAt(new Date(Long.parseLong(props.get("last_heartbeat_at")))); instance.setStartedAt(new Date(Long.parseLong(props.get("started_at")))); if (event.getPayload() != null) { try { InstanceInfo info = objectMapper.readValue(event.getPayload(), InstanceInfo.class); instance.setHostname(info.getHostname()); instance.setIp(info.getIp()); instance.setVersion(info.getVersion()); instance.setTags(info.getTags()); instance.setOperatingSystemName(info.getSystemProperties().get("os.name")); } catch (IOException ioe) { LOGGER.error("Unexpected error while getting instance informations from event payload", ioe); } } if (event.getType() == EventType.GATEWAY_STARTED) { instance.setState(InstanceState.STARTED); // If last heartbeat timestamp is < now - 5m, set as unknown state Instant lastHeartbeat = Instant.ofEpochMilli(instance.getLastHeartbeatAt().getTime()); if (lastHeartbeat.isBefore(nowMinusXMinutes)) { instance.setState(InstanceState.UNKNOWN); } } else { instance.setState(InstanceState.STOPPED); instance.setStoppedAt(new Date(Long.parseLong(props.get("stopped_at")))); } return instance; }).collect(Collectors.toList()); }
From source file:com.yahoo.egads.models.tsmm.TestOlympicModel2.java
@Test public void ctor() throws Exception { OlympicModel2 model = new OlympicModel2(config); assertEquals(5, model.interval);//ww w. jav a 2 s .c o m assertEquals(ChronoUnit.MINUTES, model.intervalUnits); assertEquals(1, model.windowDistanceInterval); assertEquals(ChronoUnit.WEEKS, model.windowDistanceIntervalUnits); assertEquals(4, model.pastWindows); assertEquals(start, model.modelStartEpoch); assertEquals(ZoneId.of("UTC"), model.zone); assertFalse(model.weighting); assertEquals(1, model.futureWindows); assertEquals(0, model.drop_highest); assertEquals(0, model.drop_lowest); assertEquals(4, model.windowTimes.length); assertEquals(4, model.indices.length); assertTrue(model.model.isEmpty()); // overrides config.clear(); config.put("INTERVAL", "5"); config.put("INTERVAL_UNITS", "MINUTES"); config.put("WINDOW_SIZE", "1"); config.put("WINDOW_SIZE_UNITS", "HOURS"); config.put("WINDOW_DISTANCE", "1"); config.put("WINDOW_DISTANCE_UNITS", "WEEKS"); config.put("HISTORICAL_WINDOWS", "4"); config.put("MODEL_START", Long.toString(start)); config.put("TIMEZONE", "Australia/Lord_Howe"); config.put("ENABLE_WEIGHTING", "true"); config.put("FUTURE_WINDOWS", "2"); config.put("NUM_TO_DROP_HIGHEST", "4"); config.put("NUM_TO_DROP_LOWEST", "8"); model = new OlympicModel2(config); assertEquals(5, model.interval); assertEquals(ChronoUnit.MINUTES, model.intervalUnits); assertEquals(1, model.windowDistanceInterval); assertEquals(ChronoUnit.WEEKS, model.windowDistanceIntervalUnits); assertEquals(4, model.pastWindows); assertEquals(start, model.modelStartEpoch); assertEquals(ZoneId.of("Australia/Lord_Howe"), model.zone); assertTrue(model.weighting); assertEquals(2, model.futureWindows); assertEquals(4, model.drop_highest); assertEquals(8, model.drop_lowest); assertEquals(4, model.windowTimes.length); assertEquals(4, model.indices.length); assertTrue(model.model.isEmpty()); // null config, underlying ctor throws an NPE, should fix it. try { model = new OlympicModel2(null); fail("Expected NullPointerException"); } catch (NullPointerException e) { } // Empty config config.clear(); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } // lots of missing required values tests. setConfig(); config.remove("INTERVAL"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("INTERVAL_UNITS"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("WINDOW_SIZE"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("WINDOW_SIZE_UNITS"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("WINDOW_DISTANCE"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("WINDOW_DISTANCE_UNITS"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.remove("MODEL_START"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); model = new OlympicModel2(config); assertEquals(1, model.pastWindows); assertEquals(ZoneId.of("UTC"), model.zone); // invalid params tests setConfig(); config.setProperty("WINDOW_SIZE", "not a number"); try { model = new OlympicModel2(config); fail("Expected NumberFormatException"); } catch (NumberFormatException e) { } setConfig(); config.setProperty("WINDOW_SIZE_UNITS", "not a unit"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.setProperty("WINDOW_DISTANCE", "not a number"); try { model = new OlympicModel2(config); fail("Expected NumberFormatException"); } catch (NumberFormatException e) { } setConfig(); config.setProperty("WINDOW_DISTANCE_UNITS", "not a unit"); try { model = new OlympicModel2(config); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } setConfig(); config.setProperty("MODEL_START", "not a number"); try { model = new OlympicModel2(config); fail("Expected NumberFormatException"); } catch (NumberFormatException e) { } }
From source file:de.qaware.chronix.solr.type.metric.functions.analyses.Frequency.java
/** * The frequency detector splits a time series into windows, counts the data points, and checks if the delta * between two windows is above a predefined threshold. * <p>//from ww w. j ava 2 s. c om * The frequency detector splits a time series using the constructor argument. * * @param functionValueMap * @return true if the time series has a pair of windows 1 and 2 where 2 has th */ @Override public void execute(MetricTimeSeries timeSeries, FunctionValueMap functionValueMap) { LongList timestamps = timeSeries.getTimestamps(); final List<Long> currentWindow = new ArrayList<>(); final List<Integer> windowCount = new ArrayList<>(); //start and end of the window long windowStart = timestamps.get(0); //calculate the end long windowEnd = Instant.ofEpochMilli(windowStart).plus(windowSize, ChronoUnit.MINUTES).toEpochMilli(); for (int i = 1; i < timeSeries.size(); i++) { long current = timestamps.get(i); //Add the occurrence of the current window. if (current > windowStart - 1 && current < (windowEnd)) { currentWindow.add(current); } else { //We reached the end. Lets add it to the window count windowCount.add(currentWindow.size()); windowStart = current; windowEnd = Instant.ofEpochMilli(windowStart).plus(windowSize, ChronoUnit.MINUTES).toEpochMilli(); currentWindow.clear(); } } //we are done, add the last window windowCount.add(currentWindow.size()); //check deltas for (int i = 1; i < windowCount.size(); i++) { int former = windowCount.get(i - 1); int current = windowCount.get(i); //The threshold int result = current - former; if (result >= windowThreshold) { //add the time series as there are more points per window than the threshold functionValueMap.add(this, true, null); return; } } //Nothing bad found functionValueMap.add(this, false, null); }
From source file:de.qaware.chronix.solr.query.analysis.functions.analyses.Frequency.java
/** * Detects if a points occurs multiple times within a defined time range * * @param args the time series/*from w w w. j a v a 2 s . c o m*/ * @return 1 if there are more points than the defined threshold, otherwise -1 */ @Override public boolean execute(MetricTimeSeries... args) { if (args.length <= 0) { throw new IllegalArgumentException("Frequency needs at least one time series"); } MetricTimeSeries timeSeries = args[0]; LongList timestamps = timeSeries.getTimestamps(); final List<Long> currentWindow = new ArrayList<>(); final List<Integer> windowCount = new ArrayList<>(); //start and end of the window long windowStart = timestamps.get(0); //calculate the end long windowEnd = Instant.ofEpochMilli(windowStart).plus(windowSize, ChronoUnit.MINUTES).toEpochMilli(); for (int i = 1; i < timeSeries.size(); i++) { long current = timestamps.get(i); //Add the occurrence of the current window. if (current > windowStart - 1 && current < (windowEnd)) { currentWindow.add(current); } else { //We reached the end. Lets add it to the window count windowCount.add(currentWindow.size()); windowStart = current; windowEnd = Instant.ofEpochMilli(windowStart).plus(windowSize, ChronoUnit.MINUTES).toEpochMilli(); currentWindow.clear(); } } //we are done, add the last window windowCount.add(currentWindow.size()); //check deltas for (int i = 1; i < windowCount.size(); i++) { int former = windowCount.get(i - 1); int current = windowCount.get(i); //The threshold int result = current - former; if (result >= windowThreshold) { //add the time series as there are more points per window than the threshold return true; } } //Nothing bad found return false; }