/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
@Override @Nullable public Object convert(@Nullable String value) { if (isNullOrEmpty(value)) { return null; } LOG.debug("Trying to parse date <{}> with pattern <{}>, locale <{}>, and timezone <{}>.", value, dateFormat, locale, timeZone); final DateTimeFormatter formatter; if (containsTimeZone) { formatter = DateTimeFormat .forPattern(dateFormat) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withLocale(locale); } else { formatter = DateTimeFormat .forPattern(dateFormat) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withLocale(locale) .withZone(timeZone); } return DateTime.parse(value, formatter); } }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
@Override @Nullable public Object convert(@Nullable String value) { if (isNullOrEmpty(value)) { return null; } LOG.debug("Trying to parse date <{}> with pattern <{}> and timezone <{}>.", value, dateFormat, timeZone); final DateTimeFormatter formatter = DateTimeFormat .forPattern(dateFormat) .withLocale(locale) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withZone(timeZone); return DateTime.parse(value, formatter); } }
private int getIntervalColumnsCount(Date intervalFrom, Date intervalTo) { YearMonth yearMonthStart = new YearMonth(intervalFrom.getTime()); YearMonth yearMonthEnd = new YearMonth(intervalTo.getTime()); int yearsDifference = yearMonthEnd.getYear() - yearMonthStart.getYear(); int monthsDifference = yearMonthEnd.getMonthOfYear() - yearMonthStart.getMonthOfYear(); return 1 + yearsDifference * 12 + monthsDifference; }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
/** * Converts this object to a LocalDate with the same year-month and chronology. * * @param dayOfMonth the day of month to use, valid for chronology, such as 1-31 for ISO * @return a LocalDate with the same year-month and chronology, never null */ public LocalDate toLocalDate(int dayOfMonth) { return new LocalDate(getYear(), getMonthOfYear(), dayOfMonth, getChronology()); }
@Test(dataProvider = "string2ym") public void testString2Java8YearMonth(String s, YearMonth ym) throws Exception { String2Java8YearMonth convertor = new String2Java8YearMonth(); Assert.assertEquals(convertor.convert(s), java.time.YearMonth.of(ym.getYear(), ym.getMonthOfYear())); } }
private PersistableMonthItem getMonthItem(PersistablePublicationDownload download, PersistableAbstractReportItem<?> item) { YearMonth yearMonth = new YearMonth(download.getDownloadDate()); for (PersistableMonthItem monthItem : item.getMonthCounts()) { YearMonth itemYearMonth = new YearMonth(monthItem.getYear(), monthItem.getMonth()); if (itemYearMonth.equals(yearMonth)) { return monthItem; } } PersistableMonthItem monthItem = new PersistableMonthItem(); monthItem.setReportItem(item); monthItem.setMonth(yearMonth.getMonthOfYear()); monthItem.setYear(yearMonth.getYear()); item.getMonthCounts().add(monthItem); return monthItem; }