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

The following examples show how to use java.time.LocalDate#minusDays() . 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: TCKLocalDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(4, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);

        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 2
Source File: RelativeDate.java    From baleen with Apache License 2.0 6 votes vote down vote up
private void createRelativeWeek(
    TextBlock block, Integer charBegin, Integer charEnd, Integer weekOffset) {
  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 && weekOffset != null) {
    LocalDate startOfWeek = relativeTo.plusWeeks(weekOffset);

    while (startOfWeek.getDayOfWeek() != DayOfWeek.MONDAY) {
      startOfWeek = startOfWeek.minusDays(1);
    }

    t.setTimestampStart(startOfWeek.atStartOfDay(ZoneOffset.UTC).toEpochSecond());

    LocalDate endOfWeek = startOfWeek.plusWeeks(1);
    t.setTimestampStop(endOfWeek.atStartOfDay(ZoneOffset.UTC).toEpochSecond());
  }

  addToJCasIndex(t);
}
 
Example 3
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(String.valueOf(i), dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 4
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 5
Source File: TCKLocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(4, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);

        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 6
Source File: TCKLocalDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_one() {
    LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    for (int i = 0; i < 50; i++) {
        t = t.minusHours(1);

        if (i % 24 == 0) {
            d = d.minusDays(1);
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
    }
}
 
Example 7
Source File: TCKLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_one() {
    LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    for (int i = 0; i < 50; i++) {
        t = t.minusHours(1);

        if (i % 24 == 0) {
            d = d.minusDays(1);
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
    }
}
 
Example 8
Source File: TCKLocalDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 9
Source File: TCKLocalDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_one() {
    LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    for (int i = 0; i < 50; i++) {
        t = t.minusHours(1);

        if (i % 24 == 0) {
            d = d.minusDays(1);
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
    }
}
 
Example 10
Source File: DbJob.java    From litemall with MIT License 6 votes vote down vote up
@Scheduled(cron = "0 0 5 * * ?")
public void backup() throws IOException {
    logger.info("系统开启定时任务数据库备份");

    String user = environment.getProperty("spring.datasource.druid.username");
    String password = environment.getProperty("spring.datasource.druid.password");
    String url = environment.getProperty("spring.datasource.druid.url");
    int index1 = url.indexOf("3306/");
    int index2 = url.indexOf("?");
    String db = url.substring(index1+5, index2);

    LocalDate localDate = LocalDate.now();
    String fileName = localDate.toString();
    File file = new File("backup", fileName);
    file.getParentFile().mkdirs();
    file.createNewFile();

    // 备份今天数据库
    DbUtil.backup(file, user, password, db);
    // 删除七天前数据库备份文件
    LocalDate before = localDate.minusDays(7);
    File fileBefore = new File("backup", fileName);
    fileBefore.deleteOnExit();

    logger.info("系统结束定时任务数据库备份");
}
 
Example 11
Source File: TCKLocalDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(4, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);

        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 12
Source File: TCKLocalDateTime.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
Example 13
Source File: SaleOrderController.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
public void setNextInvoicingStartPeriodDate(ActionRequest request, ActionResponse response) {

    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);

    TemporalUnit temporalUnit = ChronoUnit.MONTHS;

    if (saleOrder.getPeriodicityTypeSelect() != null
        && saleOrder.getNextInvoicingStartPeriodDate() != null) {
      LocalDate invoicingPeriodStartDate = saleOrder.getNextInvoicingStartPeriodDate();
      if (saleOrder.getPeriodicityTypeSelect() == 1) {
        temporalUnit = ChronoUnit.DAYS;
      }
      LocalDate subscriptionToDate =
          invoicingPeriodStartDate.plus(saleOrder.getNumberOfPeriods(), temporalUnit);
      subscriptionToDate = subscriptionToDate.minusDays(1);
      response.setValue("nextInvoicingEndPeriodDate", subscriptionToDate);
    }
  }
 
Example 14
Source File: GlobalHolidayCalendars.java    From Strata with Apache License 2.0 5 votes vote down vote up
private static LocalDate bumpToFriOrMon(LocalDate date) {
  if (date.getDayOfWeek() == SATURDAY) {
    return date.minusDays(1);
  } else if (date.getDayOfWeek() == SUNDAY) {
    return date.plusDays(1);
  }
  return date;
}
 
Example 15
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
protected CalendarViewListModel(LocalDate date) {
  super();
  LocalDate firstDayOfMonth = YearMonth.from(date).atDay(1);
  WeekFields weekFields = WeekFields.of(Locale.getDefault());
  int fdmDow = firstDayOfMonth.get(weekFields.dayOfWeek()) - 1;
  startDate = firstDayOfMonth.minusDays(fdmDow);
}
 
Example 16
Source File: PointsResourceIntTest.java    From 21-points with Apache License 2.0 4 votes vote down vote up
@Test
@Transactional
public void getPointsByMonth() throws Exception {
    LocalDate today = LocalDate.now();
    LocalDate thisMonday = today.with(DayOfWeek.MONDAY);
    LocalDate lastMonday = thisMonday.minusDays(7);
    createPointsByWeek(thisMonday, lastMonday);

    // create security-aware mockMvc
    restPointsMockMvc = MockMvcBuilders
        .webAppContextSetup(context)
        .apply(springSecurity())
        .build();

    // Get the points for last month
    DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM");
    String startDate = fmt.format(today.withDayOfMonth(1));
    LocalDate firstDate = thisMonday.plusDays(2);
    LocalDate secondDate = thisMonday.plusDays(3);

    // see if adding days takes you into next month
    if (today.getMonthValue() < firstDate.getMonthValue() || today.getMonthValue() < secondDate.getMonthValue()) {
        // if so, look for second set of dates
        firstDate = lastMonday.plusDays(3);
        secondDate = lastMonday.plusDays(4);
    }

    // see if this Monday is in different month from today
    // if so, use last month as the start date
    if (thisMonday.getMonthValue() < today.getMonthValue()) {
        startDate = fmt.format(thisMonday.withDayOfMonth(1));
        firstDate = lastMonday.plusDays(3);
        secondDate = lastMonday.plusDays(4);
    }

    restPointsMockMvc.perform(get("/api/points-by-month/{yearWithMonth}", startDate)
        .with(user("user").roles("USER")))
        .andDo(print())
        .andExpect(status().isOk())
        .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.month").value(startDate))
        .andExpect(jsonPath("$.points.[*].date").value(hasItem(firstDate.toString())))
        .andExpect(jsonPath("$.points.[*].date").value(hasItem(secondDate.toString())));
}
 
Example 17
Source File: DateFiltersTest.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Test
public void testColumnComparisons() {
  LocalDate dateTime = LocalDate.of(2015, 1, 25);
  DateColumn dateColumn = DateColumn.create("test");

  LocalDate beforeDate = dateTime.minusDays(1);
  LocalDate afterDate = dateTime.plusDays(1);

  dateColumn.append(beforeDate);
  dateColumn.append(dateTime);
  dateColumn.append(afterDate);

  DateColumn same = DateColumn.create("same");
  same.append(beforeDate);
  same.append(dateTime);
  same.append(afterDate);

  DateColumn before = DateColumn.create("before");
  before.append(beforeDate.minusDays(1));
  before.append(dateTime.minusDays(1));
  before.append(afterDate.minusDays(1));

  DateColumn after = DateColumn.create("after");
  after.append(beforeDate.plusDays(1));
  after.append(dateTime.plusDays(1));
  after.append(afterDate.plusDays(1));

  Table t = Table.create("test", dateColumn, same, before, after);

  assertTrue(dateColumn.isOnOrAfter(same).contains(0));
  assertTrue(t.dateColumn("test").isOnOrAfter(same).contains(0));
  assertTrue(t.dateColumn("test").isOnOrAfter(t.dateColumn("same")).contains(0));

  assertTrue(dateColumn.isOnOrBefore(same).contains(0));
  assertTrue(t.dateColumn("test").isOnOrBefore(same).contains(0));
  assertTrue(t.dateColumn("test").isOnOrBefore(t.dateColumn("same")).contains(0));

  assertTrue(dateColumn.isEqualTo(same).contains(0));
  assertTrue(t.dateColumn("test").isEqualTo(same).contains(0));
  assertTrue(t.dateColumn("test").isEqualTo(t.dateColumn("same")).contains(0));

  assertTrue(dateColumn.isBefore(after).contains(0));
  assertFalse(dateColumn.isOnOrAfter(after).contains(0));
  assertTrue(t.dateColumn("test").isBefore(after).contains(0));
  assertTrue(t.dateColumn("test").isBefore(t.dateColumn("after")).contains(0));

  assertTrue(dateColumn.isAfter(before).contains(0));
  assertFalse(dateColumn.isOnOrBefore(before).contains(0));
  assertTrue(t.dateColumn("test").isAfter(before).contains(0));
  assertTrue(t.dateColumn("test").isAfter(t.dateColumn("before")).contains(0));

  assertFalse(dateColumn.isNotEqualTo(same).contains(0));
  assertFalse(t.dateColumn("test").isNotEqualTo(same).contains(0));
  assertFalse(t.dateColumn("test").isNotEqualTo(t.dateColumn("same")).contains(0));

  assertTrue(dateColumn.isOnOrBefore(same).contains(0));
  assertTrue(dateColumn.isOnOrBefore(after).contains(0));
  assertFalse(dateColumn.isOnOrBefore(before).contains(0));
  assertTrue(dateColumn.isNotEqualTo(before).contains(0));

  assertTrue(dateColumn.isOnOrAfter(same).contains(1));
  assertTrue(dateColumn.isOnOrAfter(before).contains(2));
  assertFalse(dateColumn.isOnOrAfter(after).contains(2));
  assertTrue(dateColumn.isNotEqualTo(after).contains(0));

  /*
          assertTrue(t.dateColumn("test")
                  .isOnOrAfter(t.dateColumn("same")).contains(0));
          assertTrue(t.dateColumn("test")
                  .isOnOrAfter(same).contains(0));

          assertFalse(t.dateColumn("test")
                  .isOnOrAfter(t.dateColumn("after")).contains(0));
          assertFalse(t.dateColumn("test")
                  .isOnOrAfter(after).contains(0));

          assertTrue(t.dateColumn("test")
                  .isOnOrBefore(t.dateColumn("same")).contains(0));
          assertTrue(t.dateColumn("test")
                  .isOnOrBefore(same).contains(0));

          assertTrue(t.dateColumn("test")
                  .isOnOrBefore(t.dateColumn("after")).contains(0));
          assertTrue(t.dateColumn("test")
                  .isOnOrBefore(after).contains(0));

          assertFalse(t.dateColumn("test")
                  .isOnOrBefore(t.dateColumn("before")).contains(0));
          assertFalse(t.dateColumn("test")
                  .isOnOrBefore(before).contains(0));
  */

  assertTrue(t.dateColumn("test").isNotEqualTo(t.dateColumn("before")).contains(0));
  assertTrue(t.dateColumn("test").isNotEqualTo(before).contains(0));
  assertFalse(t.dateColumn("test").isNotEqualTo(t.dateColumn("same")).contains(0));
  assertFalse(t.dateColumn("test").isNotEqualTo(same).contains(0));
}
 
Example 18
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
protected CalendarViewTableModel(LocalDate date) {
  super();
  LocalDate firstDayOfMonth = YearMonth.from(date).atDay(1);
  int v = firstDayOfMonth.get(weekFields.dayOfWeek()) - 1;
  startDate = firstDayOfMonth.minusDays(v);
}
 
Example 19
Source File: DateUtils.java    From dremio-oss with Apache License 2.0 2 votes vote down vote up
/**
 * Calculates the date of the start of the week. Sunday represents the start of the week.
 *
 * @param dateWithinWeek
 * @return
 */
public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) {
  int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue();
  dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek;
  return dateWithinWeek.minusDays(dayOfWeek);
}
 
Example 20
Source File: ResolvedCds.java    From Strata with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains the effective start date from the step-in date. 
 * 
 * @param stepinDate  the step-in date
 * @return the effective start date
 */
public LocalDate calculateEffectiveStartDate(LocalDate stepinDate) {
  LocalDate startDate = stepinDate.isAfter(getAccrualStartDate()) ? stepinDate : getAccrualStartDate();
  return protectionStart.isBeginning() ? startDate.minusDays(1) : startDate;
}