Java Code Examples for java.time.YearMonth#atEndOfMonth()

The following examples show how to use java.time.YearMonth#atEndOfMonth() . 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 createMonth(TextBlock block, Integer charBegin, Integer charEnd, YearMonth ym) {
  // Check the date isn't already covered by a range
  if (alreadyExtracted(block, charBegin, charEnd)) {
    return;
  }

  Temporal date = createExactSingleDate(block, charBegin, charEnd);

  LocalDate start = ym.atDay(1);
  LocalDate end = ym.atEndOfMonth();

  date.setTimestampStart(start.atStartOfDay(ZoneOffset.UTC).toEpochSecond());
  date.setTimestampStop(end.plusDays(1).atStartOfDay(ZoneOffset.UTC).toEpochSecond());

  addToJCasIndex(date);
  extracted.add(date);
}
 
Example 2
Source File: BloodPressureResource.java    From 21-points with Apache License 2.0 6 votes vote down vote up
/**
 * GET  /bp-by-month : get all the blood pressure readings for a particular month.
 */
@GetMapping("/bp-by-month/{date}")
@Timed
public ResponseEntity<BloodPressureByPeriod> getByMonth(@PathVariable @DateTimeFormat(pattern = "yyyy-MM") YearMonth date) {
    LocalDate firstDay = date.atDay(1);
    LocalDate lastDay = date.atEndOfMonth();

    ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneOffset.UTC);

    List<BloodPressure> readings = bloodPressureRepository.
        findAllByTimestampBetweenAndUserLoginOrderByTimestampDesc(firstDay.atStartOfDay(zonedDateTime.getZone()),
            lastDay.plusDays(1).atStartOfDay(zonedDateTime.getZone()), SecurityUtils.getCurrentUserLogin().orElse(null));

    DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");
    String yearAndMonth = fmt.format(firstDay);

    BloodPressureByPeriod response = new BloodPressureByPeriod(yearAndMonth, readings);
    return new ResponseEntity<>(response, HttpStatus.OK);
}
 
Example 3
Source File: PointsResource.java    From 21-points with Apache License 2.0 5 votes vote down vote up
/**
 * GET  /points-by-month : get all the points for a particular current month.
 */
@GetMapping("/points-by-month/{yearWithMonth}")
@Timed
public ResponseEntity<PointsPerMonth> getPointsByMonth(@PathVariable @DateTimeFormat(pattern="yyyy-MM") YearMonth yearWithMonth) {
    // Get last day of the month
    LocalDate endOfMonth = yearWithMonth.atEndOfMonth();
    List<Points> points = pointsRepository.findAllByDateBetweenAndUserLogin(yearWithMonth.atDay(1), endOfMonth, SecurityUtils.getCurrentUserLogin().orElse(null));
    PointsPerMonth pointsPerMonth = new PointsPerMonth(yearWithMonth, points);
    return new ResponseEntity<>(pointsPerMonth, HttpStatus.OK);
}
 
Example 4
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);
    }
  }
}