Java Code Examples for java.time.LocalDate#getDayOfMonth()

The following examples show how to use java.time.LocalDate#getDayOfMonth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
Example 2
Source File: TCKLocalizedPrinterParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
    DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
    Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalDate.from(parsed), date);
}
 
Example 3
Source File: TCKLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate next(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() + 1;
    if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.withDayOfMonth(1);
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() + 1);
    }
    return date.with(date.getMonth().plus(1));
}
 
Example 4
Source File: TCKLocalizedPrinterParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
    DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
    Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
    String formatted = f.format(date);
    assertEquals(formatted, text);
}
 
Example 5
Source File: LocalDateLib.java    From jdmn with Apache License 2.0 5 votes vote down vote up
public Integer day(LocalDate date) {
    if (date == null) {
        return null;
    }

    return date.getDayOfMonth();
}
 
Example 6
Source File: TCKLocalizedPrinterParser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
    DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
    Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalDate.from(parsed), date);
}
 
Example 7
Source File: TestLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate next(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() + 1;
    if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.withDayOfMonth(1);
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() + 1);
    }
    return date.with(date.getMonth().plus(1));
}
 
Example 8
Source File: LocalDatePeriodCountCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private int diffConv30v360(final LocalDate start, final LocalDate end) {
    int dayStart = start.getDayOfMonth();
    int dayEnd = end.getDayOfMonth();
    if (dayEnd == CalculatorConstants.MONTH_31_DAYS && dayStart >= CalculatorConstants.MONTH_30_DAYS) {
        dayEnd = CalculatorConstants.MONTH_30_DAYS;
    }
    if (dayStart == CalculatorConstants.MONTH_31_DAYS) {
        dayStart = CalculatorConstants.MONTH_30_DAYS;
    }
    return (end.getYear() - start.getYear()) * CalculatorConstants.YEAR_360 + (end.getMonthValue() - start.getMonthValue()) * CalculatorConstants.MONTH_30_DAYS + dayEnd - dayStart;
}
 
Example 9
Source File: FullDemo.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
/**
 * isDateAllowed, Return true if a date should be allowed, or false if a date should be
 * vetoed.
 */
@Override
public boolean isDateAllowed(LocalDate date) {
    // Disallow days 7 to 11.
    if ((date.getDayOfMonth() >= 7) && (date.getDayOfMonth() <= 11)) {
        return false;
    }
    // Disallow odd numbered saturdays.
    if ((date.getDayOfWeek() == DayOfWeek.SATURDAY) && ((date.getDayOfMonth() % 2) == 1)) {
        return false;
    }
    // Allow all other days.
    return true;
}
 
Example 10
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
Example 11
Source File: DateAdjusters.java    From Strata with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the next leap day after the input date.
 * 
 * @param input  the input date
 * @return the next leap day date
 */
static LocalDate nextLeapDay(LocalDate input) {
  // already a leap day, move forward either 4 or 8 years
  if (input.getMonthValue() == 2 && input.getDayOfMonth() == 29) {
    return ensureLeapDay(input.getYear() + 4);
  }
  // handle if before February 29 in a leap year
  if (input.isLeapYear() && input.getMonthValue() <= 2) {
    return LocalDate.of(input.getYear(), 2, 29);
  }
  // handle any other date
  return ensureLeapDay(((input.getYear() / 4) * 4) + 4);
}
 
Example 12
Source File: TCKLocalDate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
Example 13
Source File: TestLocalDate.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
Example 14
Source File: SeasonalCurve.java    From finmath-lib with Apache License 2.0 5 votes vote down vote up
@Override
public double getValue(final AnalyticModel model, final double time) {
	final LocalDate calendar = getReferenceDate().plusDays((int) Math.round(time*365));

	final int month = calendar.getMonthValue();				// Note: month = 1,2,3,...,12
	final int day   = calendar.getDayOfMonth(); 				// Note: day = 1,2,3,...,numberOfDays
	final int numberOfDays = calendar.lengthOfMonth();
	final double season = (month-1) / 12.0 + (day-1) / (double)numberOfDays / 12.0;

	return baseCurve.getValue(model, season);
}
 
Example 15
Source File: TestLocalDate.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
Example 16
Source File: DateUtils.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return the start of last month at 0am in the current timezone
 */
public static Date getStartOfLastMonth() {
	LocalDate now = LocalDate.now();
	int daysthismonth = now.getDayOfMonth();
	int dayslastmonth = now.minusDays(daysthismonth).getDayOfMonth();
	return Date.from(LocalDate.now().minusDays(daysthismonth + dayslastmonth - 1).atStartOfDay()
			.atZone(ZoneId.systemDefault()).toInstant());

}
 
Example 17
Source File: DayRollConventions.java    From Strata with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(LocalDate date) {
  ArgChecker.notNull(date, "date");
  return date.getDayOfMonth() == day ||
      (date.getMonthValue() == 2 && day >= date.lengthOfMonth() && date.getDayOfMonth() == date.lengthOfMonth());
}
 
Example 18
Source File: LocalDateExtractYearMonthDayIntegerValues.java    From tutorials with MIT License 4 votes vote down vote up
int getDay(LocalDate localDate) {
    return localDate.getDayOfMonth();
}
 
Example 19
Source File: JavatimeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
    return ld.getYear() == d.getYear() + 1900 &&
           ld.getMonthValue() == d.getMonth() + 1 &&
           ld.getDayOfMonth() == d.getDate();
}
 
Example 20
Source File: LocalDateUtils.java    From Strata with Apache License 2.0 2 votes vote down vote up
/**
 * Finds the day-of-year of the date.
 * <p>
 * Faster than the JDK method.
 * 
 * @param date  the date to query
 * @return the day-of-year
 */
static int doy(LocalDate date) {
  int[] lookup = (date.isLeapYear() ? LEAP : STANDARD);
  return lookup[date.getMonthValue()] + date.getDayOfMonth();
}