@Test public void testDate() { // Note: there is identical test for PostgreSQL ZoneId jvmZone = ZoneId.systemDefault(); checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone"); LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1); verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty()); ZoneId someZone = ZoneId.of("Europe/Vilnius"); LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1); verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty()); LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1); verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2); DataTypeTest testCases = DataTypeTest.create() .addRoundTrip(dateDataType(), LocalDate.of(1952, 4, 3)) // before epoch .addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1)) .addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3)) .addRoundTrip(dateDataType(), LocalDate.of(2017, 7, 1)) // summer on northern hemisphere (possible DST) .addRoundTrip(dateDataType(), LocalDate.of(2017, 1, 1)) // winter on northern hemisphere (possible DST on southern hemisphere) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone); for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) { Session session = Session.builder(getQueryRunner().getDefaultSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)) .build(); testCases.execute(getQueryRunner(), session, mysqlCreateAndInsert("tpch.test_date")); testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date")); } }
@Test public void testDate() { // Note: there is identical test for MySQL ZoneId jvmZone = ZoneId.systemDefault(); checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone"); LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1); verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty()); ZoneId someZone = ZoneId.of("Europe/Vilnius"); LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1); verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty()); LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1); verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2); DataTypeTest testCases = DataTypeTest.create() .addRoundTrip(dateDataType(), LocalDate.of(1952, 4, 3)) // before epoch .addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1)) .addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3)) .addRoundTrip(dateDataType(), LocalDate.of(2017, 7, 1)) // summer on northern hemisphere (possible DST) .addRoundTrip(dateDataType(), LocalDate.of(2017, 1, 1)) // winter on northern hemisphere (possible DST on southern hemisphere) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone) .addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone); for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) { Session session = Session.builder(getQueryRunner().getDefaultSession()) .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)) .build(); testCases.execute(getQueryRunner(), session, postgresCreateAndInsert("tpch.test_date")); testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date")); } }
public void subtract_minutes_from_date_in_java8 () { LocalDateTime newYearsDay = LocalDateTime.of(2015, Month.JANUARY, 1, 0, 0); LocalDateTime newYearsEve = newYearsDay.minusMinutes(1);// In your case use 5 here java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss S"); logger.info(newYearsDay.format(formatter)); logger.info(newYearsEve.format(formatter)); }
public static boolean isStuck(String containerId) { List<LocalDateTime> datesOfRestart = restarts.computeIfAbsent(containerId, k -> new ArrayList<>()); LocalDateTime now = LocalDateTime.now(); datesOfRestart.removeIf(dateOfRestart -> dateOfRestart.isBefore(now.minusMinutes(INTERVAL_IN_MINUTES))); datesOfRestart.add(now); return datesOfRestart.size() >= ABNORMAL_NUMBER_OF_RESTARTS; } }
LocalDateTime dt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(1429174464829L), ZoneId.systemDefault()); LocalDateTime dt2 = LocalDateTime.now().plusDays(1); System.out.println(dt1); System.out.println(dt2); StringJoiner sj = new StringJoiner(":"); long hours = ChronoUnit.HOURS.between(dt1, dt2); sj.add(Long.toString(hours)); dt2 = dt2.minusHours(hours); long mins = ChronoUnit.MINUTES.between(dt1, dt2); sj.add(Long.toString(mins)); dt2 = dt2.minusMinutes(mins); long secs = ChronoUnit.SECONDS.between(dt1, dt2); sj.add(Long.toString(secs)); System.out.println(sj);
private boolean isCacheValid(File filePath) { LocalDateTime lastChecked = updateTimesMap.get(filePath); LocalDateTime invalidateDeadline = LocalDateTime.now() .minusMinutes(updateTimeoutMinutes); return invalidateDeadline.isBefore(lastChecked); }
public boolean doWeQueryAgainAllTime(Metric queriedMetric) { if (null == queriedMetric) { //never queried before return true; } int minutesUntilNextQuery = systemConfig.getMetricsCacheTimeoutMinutes(); Date lastCalled = queriedMetric.getLastCalledDate(); LocalDateTime ldt = LocalDateTime.ofInstant((new Date()).toInstant(), ZoneId.systemDefault()); LocalDateTime ldtMinus = ldt.minusMinutes(minutesUntilNextQuery); Date todayMinus = Date.from(ldtMinus.atZone(ZoneId.systemDefault()).toInstant()); //allow if today minus query wait is after last called time return (todayMinus.after(lastCalled)); }
/** * Creates a date range filtering on the last 15 minutes. * * @return a date range for the given interval */ public static DateRange lastFiveteenMinutes() { return new DateRange("15m", NLS.get("DateRange.15m"), LocalDateTime.now().minusMinutes(15), LocalDateTime.now()); }
/** * Creates a date range filtering on the last five minutes. * * @return a date range for the given interval */ public static DateRange lastFiveMinutes() { return new DateRange("5m", NLS.get("DateRange.5m"), LocalDateTime.now().minusMinutes(5), LocalDateTime.now()); }
public static boolean isTrustedServiceUrl(URL url) { return !_trustHostNames.getOrDefault(url.getHost(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5)); }
/** * Creates a date range filtering on the last five minutes. * * @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)} */ public static DateRange lastFiveMinutes() { return new DateRange("5m", NLS.get("DateRange.5m"), LocalDateTime.now().minusMinutes(5), LocalDateTime.now()); }
/** * Creates a date range filtering on the last 15 minutes. * * @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)} */ public static DateRange lastFiveteenMinutes() { return new DateRange("15m", NLS.get("DateRange.15m"), LocalDateTime.now().minusMinutes(15), LocalDateTime.now()); }
public static boolean isTrustedServiceUrl(URL url) { return !trustHostNames.getOrDefault(url.getHost(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5)); }
public boolean doWeQueryAgainMonthly(Metric queriedMetric) { if (null == queriedMetric) { //never queried before return true; } String yyyymm = queriedMetric.getMetricDateString(); String thisMonthYYYYMM = MetricsUtil.getCurrentMonth(); Date lastCalled = queriedMetric.getLastCalledDate(); LocalDateTime ldt = LocalDateTime.ofInstant((new Date()).toInstant(), ZoneId.systemDefault()); int minutesUntilNextQuery = systemConfig.getMetricsCacheTimeoutMinutes(); if (yyyymm.equals(thisMonthYYYYMM)) { //if this month LocalDateTime ldtMinus = ldt.minusMinutes(minutesUntilNextQuery); Date todayMinus = Date.from(ldtMinus.atZone(ZoneId.systemDefault()).toInstant()); //allow if today minus query wait is after last called time return (todayMinus.after(lastCalled)); } else { String lastRunYYYYMM = yyyymmFormat.format(lastCalled); //if queried was last run during the month it was querying. //Allows one requery of a past month to make it up to date. return (lastRunYYYYMM.equals(yyyymm)); } }
public static boolean isTrustedServiceUrl(HttpUrl url) { return !trustHostNames.getOrDefault(url.host(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5)); }
@Scheduled(fixedRate = 120000) public void getResult() { LocalDateTime time = LocalDateTime.now(); Date end = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); time.minusDays(1); time.minusMinutes(60); Date start = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); imgFileRepository.findByGreenStatus(1, start, end).forEach(img -> { try { float checkResult = greenService.getCheckResult(img.getGreenTaskId()); boolean porn = checkResult > 90; imgFileRepository.updateGreenStatusById(porn ? 3 : 5, img.getId()); imgFileRepository.updateGreenPointById(checkResult, img.getId()); } catch (Throwable throwable) { imgFileRepository.updateGreenStatusById(4, img.getId()); } }); } };
@Override protected void onExecute (@Nonnull final JobDataMap aJobDataMap, @Nonnull final IJobExecutionContext aContext) throws JobExecutionException { final long nMins = aJobDataMap.getAsLong (KEY_MINUTES); final LocalDateTime aOldDT = PDTFactory.getCurrentLocalDateTime ().minusMinutes (nMins); final ICommonsList <String> aEvicted = MetaAS4Manager.getIncomingDuplicateMgr ().evictAllItemsBefore (aOldDT); if (aEvicted.isNotEmpty ()) LOGGER.info ("Evicted " + aEvicted.size () + " incoming duplicate message IDs"); }
private static String formatSpokenRecentDateWithTime(LocalDateTime givenDateTime) { if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(30))) { return NLS.get("NLS.someMinutesAgo"); } if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(59))) { return NLS.fmtr("NLS.nMinutesAgo") .set("minutes", Duration.between(givenDateTime, LocalDateTime.now()).toMinutes()) .format(); } if (givenDateTime.isAfter(LocalDateTime.now().minusHours(2))) { return NLS.get("NLS.oneHourAgo"); } return NLS.fmtr("NLS.nHoursAgo") .set("hours", Duration.between(givenDateTime, LocalDateTime.now()).toHours()) .format(); }
private boolean wouldExceedNextFixedEvent(Activity activityToAdd, Queue<Event> fixedEventQueue, Event lastEvent) { if (!fixedEventQueue.isEmpty()) { Event eventToAdd = activityToEvent(lastEvent, activityToAdd); Event nextFixedEvent = fixedEventQueue.peek(); double travelTime = travelTime(activityToAdd, nextFixedEvent.getActivity()); return wouldExceedTime(eventToAdd, nextFixedEvent.getEventTime().getStart().minusMinutes((int) travelTime)); } else { return false; } }
private Activity createPlaceholderActivity(Event fixedEvent, Event lastEvent) { final Location location; final long duration; if (lastEvent != null) { location = lastEvent.getActivity().getLocation(); LocalDateTime endOfLastEvent = lastEvent.getEventTime().getEnd(); double travelTimeFromLastEvent = travelTime(lastEvent.getActivity(), fixedEvent.getActivity()); LocalDateTime timeToStartFixedEvent = fixedEvent.getEventTime().getStart().minusMinutes((int) travelTimeFromLastEvent); duration = between(endOfLastEvent, timeToStartFixedEvent).toMinutes(); } else { location = fixedEvent.getActivity().getLocation(); LocalDateTime timeToStartFixedEvent = fixedEvent.getEventTime().getStart(); duration = between(startTime, timeToStartFixedEvent).toMinutes(); } return createActivity("placeholder event", duration, location, ActivityType.PLACEHOLDER); }