Java Code Examples for java.time.Year#atMonth()

The following examples show how to use java.time.Year#atMonth() . 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: Date.java    From baleen with Apache License 2.0 6 votes vote down vote up
private void createDateFromMatcher(
    TextBlock block, Matcher m, Integer yearGroup, Integer monthGroup, Integer dayGroup) {
  Year y = DateTimeUtils.asYear(m.group(yearGroup));

  String month = m.group(monthGroup);
  if (month.endsWith(".")) {
    month = month.substring(0, month.length() - 1);
  }

  YearMonth ym = y.atMonth(DateTimeUtils.asMonth(month));

  LocalDate ld;
  try {
    ld = ym.atDay(Integer.parseInt(m.group(dayGroup)));
  } catch (DateTimeException dte) {
    getMonitor().warn(INVALID_DATE_FOUND, dte);
    return;
  }

  createDate(block, m.start(), m.end(), ld);
}
 
Example 2
Source File: RelativeDate.java    From baleen with Apache License 2.0 6 votes vote down vote up
private void createRelativeYearMonth(
    TextBlock block, Integer charBegin, Integer charEnd, Integer yearOffset, Month month) {
  Temporal t = new Temporal(block.getJCas());
  block.setBeginAndEnd(t, charBegin, charEnd);

  t.setConfidence(1.0);
  t.setPrecision(PRECISION_RELATIVE);
  t.setScope(SCOPE_SINGLE);
  t.setTemporalType(TYPE_DATE);

  if (relativeTo != null && yearOffset != null) {
    Year y = Year.from(relativeTo).plusYears(yearOffset);
    YearMonth ym = y.atMonth(month);

    t.setTimestampStart(ym.atDay(1).atStartOfDay(ZoneOffset.UTC).toEpochSecond());
    t.setTimestampStop(
        ym.atEndOfMonth().plusDays(1).atStartOfDay(ZoneOffset.UTC).toEpochSecond());
  }

  addToJCasIndex(t);
}
 
Example 3
Source File: TCKYear.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 4
Source File: TCKYear.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 5
Source File: TCKYear.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 6
Source File: TCKYear.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 7
Source File: TCKYear.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 8
Source File: TCKYear.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 9
Source File: TCKYear.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 10
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 11
Source File: Date.java    From baleen with Apache License 2.0 4 votes vote down vote up
private void identifyMonths(TextBlock block) {
  Pattern monthYear =
      Pattern.compile(
          "\\b((beginning of|start of|early|mid|late|end of)[- ])?"
              + MONTHS
              + "\\s+(\\d{4}|'?\\d{2}\\b)",
          Pattern.CASE_INSENSITIVE);
  String text = block.getCoveredText();
  Matcher m = monthYear.matcher(text);

  while (m.find()) {
    Year y = DateTimeUtils.asYear(m.group(16));
    String month = m.group(3);

    if (month.endsWith(".")) {
      month = month.substring(0, month.length() - 1);
    }

    YearMonth ym = y.atMonth(DateTimeUtils.asMonth(month));

    if (m.group(2) != null) {
      LocalDate ld1;
      LocalDate ld2;
      switch (m.group(2).toLowerCase()) {
        case "beginning of":
        case "start of":
          ld1 = ym.atDay(1);
          ld2 = ym.atDay(5);
          break;
        case "early":
          ld1 = ym.atDay(1);
          ld2 = ym.atDay(10);
          break;
        case "mid":
          ld1 = ym.atDay(11);
          ld2 = ym.atDay(20);
          break;
        case "late":
          ld1 = ym.atDay(21);
          ld2 = ym.atEndOfMonth();
          break;
        case "end of":
          ld1 = ym.atEndOfMonth().minusDays(5);
          ld2 = ym.atEndOfMonth();
          break;
        default:
          continue;
      }

      createDayMonthYearRange(block, m.start(), m.end(), ld1, ld2);
    } else {
      createMonth(block, m.start(), m.end(), ym);
    }
  }
}
 
Example 12
Source File: TCKYear.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 13
Source File: TCKYear.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 14
Source File: TCKYear.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 15
Source File: TCKYear.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 16
Source File: TCKYear.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 17
Source File: TCKYear.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 18
Source File: TCKYear.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 19
Source File: TCKYear.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@link java.time.YearMonth} of this year and the provided {@link java.time.Month}.
 *
 * @param self  a Year
 * @param month a Month
 * @return a YearMonth
 * @since 2.5.0
 */
public static YearMonth leftShift(final Year self, Month month) {
    return self.atMonth(month);
}