List of usage examples for java.time LocalDate isBefore
@Override public boolean isBefore(ChronoLocalDate other)
From source file:Main.java
public static void main(String[] args) { LocalDate a = LocalDate.of(2014, 6, 30); LocalDate b = LocalDate.of(2014, 7, 1); System.out.println(a.isBefore(b)); System.out.println(a.isBefore(a)); System.out.println(b.isBefore(a)); }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); LocalDate tomorrow = today.plusDays(1); LocalDate yesterday = today.minus(1, DAYS); if (tomorrow.isAfter(today)) { System.out.println("Tomorrow comes after today"); }//from w w w .j a v a 2 s . c o m if (yesterday.isBefore(today)) { System.out.println("Yesterday is day before today"); } }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); LocalDate nextBDay = birthday.withYear(today.getYear()); //If your birthday has occurred this year already, add 1 to the year. if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) { nextBDay = nextBDay.plusYears(1); }//from w w w . jav a 2s . c om Period p = Period.between(today, nextBDay); long p2 = ChronoUnit.DAYS.between(today, nextBDay); System.out.println("There are " + p.getMonths() + " months, and " + p.getDays() + " days until your next birthday. (" + p2 + " total)"); }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); // Get the Year, check if it's leap year System.out.println("Year " + today.getYear() + " is Leap Year? " + today.isLeapYear()); // Compare two LocalDate for before and after System.out.println("Today is before 01/01/2015? " + today.isBefore(LocalDate.of(2015, 1, 1))); // Create LocalDateTime from LocalDate System.out.println("Current Time=" + today.atTime(LocalTime.now())); }
From source file:Main.java
/** * Calculates the number of quarters between two given dates * //from w ww . j a v a 2 s . c o m * @return Number of quarters * @param date1 * First given date cannot be null * @param date2 * Second given date cannot be null */ public static int getQuartersBetweenDates(LocalDate date1, LocalDate date2) { LocalDate beginn = null; LocalDate end = null; if (date1.isBefore(date2)) { beginn = date1; end = date2; } else { beginn = date2; end = date1; } int quarters = getQuarter(end) - getQuarter(beginn); int years = end.get(ChronoField.YEAR) - beginn.get(ChronoField.YEAR); quarters += years * 4; return Math.abs(quarters); }
From source file:mesclasses.util.NodeUtil.java
/** * vrifie si une date est entre les dates fournies (incluses) * @param date/*from ww w .j a va 2s . co m*/ * @param start * @param end * @return */ public static boolean isBetween(LocalDate date, LocalDate start, LocalDate end) { if (date == null || start == null || end == null) { return false; } return (date.isAfter(start) || date.isEqual(start)) && (date.isBefore(end) || date.isEqual(end)); }
From source file:com.nridge.core.base.std.DatUtl.java
/** * Calculates the number of business days (excluding weekends) * between two dates (inclusive). In addition, this utility * method will factor in holidays (e.g. skip them in the count) * for the calculation.//from w w w. ja v a 2 s .co m * <p> * https://stackoverflow.com/questions/4600034/calculate-number-of-weekdays-between-two-dates-in-java * </p> * * @param aStartDate Start date. * @param anEndDate End date. * @param aHolidayList List of holidays to skip. * * @return Number of business days. */ public static long calculateBusinessDays(LocalDate aStartDate, LocalDate anEndDate, List<LocalDate> aHolidayList) { long totalBusinessDays = calculateBusinessDays(aStartDate, anEndDate); if ((totalBusinessDays > 0) && (aHolidayList != null)) { for (LocalDate holidayDate : aHolidayList) { if (holidayDate.isEqual(aStartDate)) totalBusinessDays--; else if (holidayDate.isEqual(anEndDate)) totalBusinessDays--; else if ((holidayDate.isAfter(aStartDate)) && (holidayDate.isBefore(anEndDate))) totalBusinessDays--; } } return Math.max(totalBusinessDays, 0); }
From source file:no.imr.stox.functions.utils.CovariateUtils.java
public static Boolean isInPeriod(LocalDate date, String period) { if (date == null || period == null) { return false; }//from w ww . j av a 2 s. c om String[] s = period.split("-"); if (s.length == 2) { Integer year = date.getYear(); LocalDate from = IMRdate.strToLocalDate(getFullPeriod(s[0], year), IMRdate.DATE_FORMAT_DMY); LocalDate to = IMRdate.strToLocalDate(getFullPeriod(s[1], year), IMRdate.DATE_FORMAT_DMY); if (IMRdate.isSameDay(date, from) || IMRdate.isSameDay(date, to) || date.isAfter(from) && date.isBefore(to)) { return true; } } return false; }
From source file:com.intuit.wasabi.api.pagination.filters.impl.ExperimentFilter.java
/** * Tests dates for more sophisticated constraints than just partial string matches. * <p>/*from w w w .jav a 2s . c o m*/ * <p> * The a filter to check these constraints has to be of the following form:<br /> * {@code is[any|on|before|after|between]:MM/dd/yyyy[:MM/dd/yyyy]} * <p> * For example to check whether the start date was before March 15, 2014 you would use a filter like:<br /> * {@code date_constraint_start=isbefore:03/15/2014} * <p> * To check if an end date lies between (inclusive!) May 4, 2013 and July 4, 2014 you would use a * filter like:<br /> * {@code date_constraint_end=isbetween:05/04/2013:07/04/2014} * <p> * Note that {@code isbetween} is the only value taking two dates and {@code isany} as well as empty strings * and {@code null} always return true. * * @param experimentDate the experiment date value to test * @param filter the filter * @return true if the constraint is fulfilled */ /*test*/ static boolean constraintTest(Date experimentDate, String filter) { String[] extracted = FilterUtil.extractTimeZone(filter); String originalFilter = extracted[0]; String timeZoneOffset = "+0000"; try { timeZoneOffset = extracted[1]; } catch (ArrayIndexOutOfBoundsException ignored) { } String[] structuredFilter = originalFilter.split(":"); if (structuredFilter.length < 2) { if (StringUtils.isBlank(structuredFilter[0]) || structuredFilter[0].equalsIgnoreCase("isAny")) { return true; } throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for constraint date ( " + filter + " ), " + "use: is[any|on|before|after|between]:MM/dd/yyyy[:MM/dd/yyyy]"); } if (StringUtils.isBlank(structuredFilter[0])) { throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for constraint date ( " + filter + " ), " + "needs one of is[any|on|before|after|between] before the colon."); } LocalDate experimentLocalDate = FilterUtil.convertDateToOffsetDateTime(experimentDate).toLocalDate(); if (structuredFilter[0].equalsIgnoreCase("isBetween")) { try { LocalDate beforeExperimentDate = FilterUtil.parseUIDate(structuredFilter[1], timeZoneOffset) .minusDays(1).toLocalDate(); LocalDate afterExperimentDate = FilterUtil.parseUIDate(structuredFilter[2], timeZoneOffset) .plusDays(1).toLocalDate(); return experimentLocalDate.isAfter(beforeExperimentDate) && experimentLocalDate.isBefore(afterExperimentDate); } catch (ArrayIndexOutOfBoundsException aioobe) { throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format for isBetween ( " + filter + " ), " + "use: isbetween:MM/dd/yyyy:MM/dd/yyyy .", aioobe); } } LocalDate filterDate = FilterUtil.parseUIDate(structuredFilter[1], timeZoneOffset).toLocalDate(); switch (structuredFilter[0].toLowerCase()) { case "isbefore": return experimentLocalDate.isBefore(filterDate); case "isafter": return experimentLocalDate.isAfter(filterDate); case "ison": return experimentLocalDate.isEqual(filterDate); } throw new PaginationException(ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format: not processable filter format ( " + filter + " )."); }
From source file:Main.java
@Override public Quarter queryFrom(TemporalAccessor temporal) { LocalDate now = LocalDate.from(temporal); if (now.isBefore(now.with(Month.APRIL).withDayOfMonth(1))) { return Quarter.FIRST; } else if (now.isBefore(now.with(Month.JULY).withDayOfMonth(1))) { return Quarter.SECOND; } else if (now.isBefore(now.with(Month.NOVEMBER).withDayOfMonth(1))) { return Quarter.THIRD; } else {//from w w w .ja v a 2 s. c o m return Quarter.FOURTH; } }