當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDate.minusDays方法代碼示例

本文整理匯總了Java中java.time.LocalDate.minusDays方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.minusDays方法的具體用法?Java LocalDate.minusDays怎麽用?Java LocalDate.minusDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDate的用法示例。


在下文中一共展示了LocalDate.minusDays方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: givenSomePast_someUpcoming_andSomeFarFutureEvents_suppliesOnlyUpcomingEvents

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void givenSomePast_someUpcoming_andSomeFarFutureEvents_suppliesOnlyUpcomingEvents() throws Exception {
    LocalDate today = LocalDate.now();
    LocalDate yesterday = today.minusDays(1);
    LocalDate tomorrow = today.plusDays(1);
    LocalDate dayAfterTomorrow = today.plusDays(2);

    eventRepository.save(new Event("Today", yesterday));
    Event eventToday = eventRepository.save(new Event("Today", today));
    Event eventTomorrow = eventRepository.save(new Event("Today", tomorrow));
    Event eventDayAfterTomorrow = eventRepository.save(new Event("Today", dayAfterTomorrow));

    assertThat(
            new FetchUpcomingEvents(eventRepository, 1).perform(today, events1 -> events1),
            containsInAnyOrder(eventToday, eventTomorrow)
    );

    assertThat(
            new FetchUpcomingEvents(eventRepository, 2).perform(today, events -> events),
            containsInAnyOrder(eventToday, eventTomorrow, eventDayAfterTomorrow)
    );
}
 
開發者ID:pivotal,項目名稱:spring-samples,代碼行數:23,代碼來源:FetchUpcomingEventsTest.java

示例2: getTaskCountForWorkbasketByDaysInPastAndState

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public long getTaskCountForWorkbasketByDaysInPastAndState(String workbasketId, long daysInPast,
    List<TaskState> states) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            "entry to getTaskCountForWorkbasketByDaysInPastAndState(workbasketId {}, daysInPast={}, states = {})",
            workbasketId, daysInPast, LoggerUtils.listToString(states));
    }
    long result = -1;
    try {
        taskanaEngineImpl.openConnection();
        LocalDate time = LocalDate.now();
        time = time.minusDays(daysInPast);
        Date fromDate = Date.valueOf(time);
        result = taskMonitorMapper.getTaskCountForWorkbasketByDaysInPastAndState(workbasketId, fromDate, states);
        return result;
    } finally {
        taskanaEngineImpl.returnConnection();
        LOGGER.debug("exit from getTaskCountForWorkbasketByDaysInPastAndState(). Returning result {} ", result);
    }
}
 
開發者ID:Taskana,項目名稱:taskana,代碼行數:22,代碼來源:TaskMonitorServiceImpl.java

示例3: getTaskCountByWorkbasketAndDaysInPastAndState

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public List<DueWorkbasketCounter> getTaskCountByWorkbasketAndDaysInPastAndState(long daysInPast,
    List<TaskState> states) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("entry to getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast = {}, states = {})",
            daysInPast, LoggerUtils.listToString(states));
    }
    List<DueWorkbasketCounter> result = null;
    try {
        taskanaEngineImpl.openConnection();
        LocalDate time = LocalDate.now();
        time = time.minusDays(daysInPast);
        Date fromDate = Date.valueOf(time);
        result = taskMonitorMapper.getTaskCountByWorkbasketIdAndDaysInPastAndState(fromDate, states);
        return result;
    } finally {
        taskanaEngineImpl.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result == null ? 0 : result.size();
            LOGGER.debug(
                "exit from getTaskCountByWorkbasketAndDaysInPastAndState(daysInPast,states). Returning {} resulting Objects: {} ",
                numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
 
開發者ID:Taskana,項目名稱:taskana,代碼行數:26,代碼來源:TaskMonitorServiceImpl.java

示例4: getReservasEmAbertoNaSemana

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public List<ReservaEntity> getReservasEmAbertoNaSemana(LocalDate data) {
	ArrayList<ReservaEntity> resultado = new ArrayList<>();

	if (!data.getDayOfWeek().equals(DayOfWeek.MONDAY))
		data = data.minusDays(data.getDayOfWeek().getValue() - 1);
	do {
		resultado.addAll(getReservasEmAbertoNoDia(data));
		data = data.plusDays(1);
	} while (!data.getDayOfWeek().equals(DayOfWeek.SUNDAY));

	for (ReservaEntity reservaEntity : resultado) {
		System.out.println(reservaEntity.getDataSolicitacao() + " " + reservaEntity.getStatus());
	}

	return resultado;
}
 
開發者ID:dev-andremonteiro,項目名稱:AlphaLab,代碼行數:18,代碼來源:MockReservaDAO.java

示例5: test_minusHours_one

import java.time.LocalDate; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TCKLocalDateTime.java

示例6: test_minusHours_fromZero

import java.time.LocalDate; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例7: test_minusHours_fromOne

import java.time.LocalDate; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKLocalDateTime.java

示例8: testSplitLocalDate

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "directions")
public void testSplitLocalDate(boolean ascending) {
    final Period step = Period.ofDays(1);
    final LocalDate start = LocalDate.of(1990, 1, 1);
    final LocalDate end = ascending ? start.plusDays(10000) : start.minusDays(10000);
    final Range<LocalDate> range = Range.of(start, end, step);
    final List<Range<LocalDate>> segments = range.split(100);
    Assert.assertTrue(segments.size() > 1, "There are multiple segments");
    for (int i=1; i<segments.size(); ++i) {
        final Range<LocalDate> prior = segments.get(i-1);
        final Range<LocalDate> next = segments.get(i);
        Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
        if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
        if (i == segments.size()-1) {
            Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:RangeSplitTests.java

示例9: localDate

import java.time.LocalDate; //導入方法依賴的package包/類
public static void localDate() {

        LocalDate now = LocalDate.now();
        LocalDate plus = now.plus(1, ChronoUnit.DAYS);
        LocalDate minus = now.minusDays(1);

        System.out.println(now); //2017-09-20
        System.out.println(plus); //2017-09-21
        System.out.println(minus); //2017-09-19

        LocalDate customDate = LocalDate.of(2017, Month.SEPTEMBER, 20);
        DayOfWeek dayOfWeek = customDate.getDayOfWeek();
        System.out.println(dayOfWeek); //WEDNESDAY 星期三

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofLocalizedDate(FormatStyle.MEDIUM)
                .withLocale(Locale.CHINA);
        LocalDate parse = LocalDate.parse("2017-09-20", dateTimeFormatter);
        System.out.println(parse); //2017-09-20
    }
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:21,代碼來源:Main.java

示例10: cleanUpSyncLog

import java.time.LocalDate; //導入方法依賴的package包/類
@Scheduled(fixedRate = 1000 * 60 * 60 * 24)
public void cleanUpSyncLog() {
    LocalDate today = LocalDate.now(ZoneId.systemDefault()) ;
    LocalDate startDate = today.minusDays(delay);
    long delayMillis = startDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();

    log.info("Deleting logs before " + startDate + " where epoch day = " + delayMillis);
    jongo.getCollection(SYNC_LOG).remove("{ epochDay: { $lte: # }}", delayMillis);
}
 
開發者ID:dizitart,項目名稱:nitrite-database,代碼行數:10,代碼來源:SyncLogCleanUpService.java

示例11: lastOpeningDay

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Returns last opening relative to passed date. If the mensa is open on that day, the date is returned
 * @param date to find last opening day for
 * @param mensa to check
 * @return last opening relative to passed date
 */
public LocalDate lastOpeningDay(LocalDate date, Mensa mensa) {
    LocalDate result = date;
    while (!isOpeningDay(result, mensa)) {
        result = result.minusDays(1);
    }
    return result;
}
 
開發者ID:xabgesagtx,項目名稱:mensa-api,代碼行數:14,代碼來源:TimeUtils.java

示例12: getAtivosNaSemana

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public List<ReservaEntity> getAtivosNaSemana(LocalDate data) {
	ArrayList<ReservaEntity> resultado = new ArrayList<>();

	if (!data.getDayOfWeek().equals(DayOfWeek.MONDAY))
		data = data.minusDays(data.getDayOfWeek().getValue() - 1);
	do {
		resultado.addAll(getAtivosNoDia(data));
		data = data.plusDays(1);
	} while (!data.getDayOfWeek().equals(DayOfWeek.SUNDAY));

	return resultado;
}
 
開發者ID:dev-andremonteiro,項目名稱:AlphaLab,代碼行數:14,代碼來源:MockReservaDAO.java

示例13: onCreateView

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.chart_frag, container, false);

    // Set up timeline chart
    chart = view.findViewById(R.id.timeline);
    entries = new ArrayList<>();

    // Set up the x-axis
    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

    formatter = DateTimeFormatter.ofPattern("MMM d");
    dates = new ArrayList<>();

    int numDays = 14;
    LocalDate today = LocalDate.now();
    minimumDate = today.minusDays(numDays);
    LocalDate currentDay = minimumDate;

    dateMap = new HashMap<>();

    for (int i = 0; i < numDays + 1; i++) {
        float index = (float) i;

        String dateString = currentDay.format(formatter);
        dates.add(dateString);
        dateMap.put(dateString, i);

        BarEntry barEntry = new BarEntry(index, new float[] { 0, 0, 0, 0 });
        entries.add(barEntry);

        currentDay = currentDay.plusDays(1);
    }

    xAxis.setValueFormatter(new MyXAxisValueFormatter(dates));
    xAxis.setLabelCount(numDays);
    xAxis.setGranularity(1f);
    xAxis.setLabelRotationAngle(45f);

    UserAccount currentUser = HabitUpApplication.getCurrentUser();

    // Get user events
    ArrayList<HabitEvent> eventList = currentUser.getEventList().getEvents();

    for (HabitEvent event : eventList) {
        if (withinDateRange(event.getCompletedate(), minimumDate)) {
            addChartEntry(event);
        }
    }

    set = new BarDataSet(entries, "");
    int red = Color.parseColor(Attributes.getColour("Physical"));
    int purple = Color.parseColor(Attributes.getColour("Mental"));
    int green = Color.parseColor(Attributes.getColour("Discipline"));
    int blue = Color.parseColor(Attributes.getColour("Social"));
    int[] colors = {red, purple, green, blue};
    set.setColors(colors);
    set.setStackLabels(new String[]{"Physical", "Mental", "Discipline", "Social"});
    set.setDrawValues(false);

    BarData data = new BarData(set);
    data.setBarWidth(0.6f);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setValueFormatter(new MyYAxisValueFormatter());
    leftAxis.setGranularity(1f);
    leftAxis.setAxisMinimum(0f);
    chart.getAxisRight().setEnabled(false);

    chart.setData(data);
    chart.setFitBars(true);
    chart.getXAxis().setDrawGridLines(false);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getDescription().setEnabled(false);
    animateChart();
    chart.invalidate();

    return view;
}
 
開發者ID:CMPUT301F17T29,項目名稱:HabitUp,代碼行數:82,代碼來源:ChartFragment.java

示例14: getTaskCountByWorkbasketAndDaysInPastAndState

import java.time.LocalDate; //導入方法依賴的package包/類
@RequestMapping(value = "/taskcountByWorkbasketDaysAndState")
public ResponseEntity<?> getTaskCountByWorkbasketAndDaysInPastAndState(
    @RequestParam(value = "daysInPast") Long daysInPast,
    @RequestParam(value = "states") List<TaskState> states) {
    try {
        WorkbasketCounterDto WorkbasketCounterDto = new WorkbasketCounterDto();

        LocalDate date = LocalDate.now();
        date = date.minusDays(daysInPast);
        List<String> dates = new ArrayList<>();

        for (int i = 0; i < (daysInPast * 2 + 1); i++) {
            dates.add(date.format(new DateTimeFormatterBuilder().appendPattern("dd.MM.yyyy").toFormatter()));
            date = date.plusDays(1);
        }
        WorkbasketCounterDto.setDates(dates);

        List<WorkbasketCounterDataDto> data = new ArrayList<>();

        for (WorkbasketSummary workbasket : workbasketService.getWorkbaskets()) {
            WorkbasketCounterDataDto counterDto = new WorkbasketCounterDataDto();
            counterDto.setLabel(workbasket.getName());
            List<Integer> zeroData = new ArrayList<>();
            for (int i = 0; i < dates.size(); i++) {
                zeroData.add(0);
            }
            counterDto.setData(zeroData);
            data.add(counterDto);
        }

        List<DueWorkbasketCounter> dwcList = taskMonitorService.getTaskCountByWorkbasketAndDaysInPastAndState(
            daysInPast,
            states);

        for (DueWorkbasketCounter item : dwcList) {
            String formattedDate = item.getDue()
                .toLocalDate()
                .format(new DateTimeFormatterBuilder().appendPattern("dd.MM.yyyy").toFormatter());
            for (int i = 0; i < dates.size(); i++) {
                if (formattedDate.equalsIgnoreCase(dates.get(i))) {
                    for (int j = 0; j < data.size(); j++) {
                        if (data.get(j).getLabel().equalsIgnoreCase(
                            workbasketService.getWorkbasket(item.getWorkbasketId()).getName())) {
                            data.get(j).getData().set(i, (int) item.getTaskCounter());
                        }
                    }
                }
            }
        }

        WorkbasketCounterDto.setData(data);

        return ResponseEntity.status(HttpStatus.OK).body(WorkbasketCounterDto);
    } catch (Exception e) {
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
 
開發者ID:Taskana,項目名稱:taskana,代碼行數:58,代碼來源:MonitorController.java

示例15: createControl

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
protected DateControl createControl() {
    CalendarSource source = new CalendarSource();
    source.setName("Demo Source");

    Calendar[] calendar = new Calendar[7];
    for (int i = 0; i < 7; i++) {
        calendar[i] = new Calendar("Calendar " + i);
        calendar[i].setStyle(Calendar.Style.getStyle(i));
    }

    for (int i = 0; i < 1000; i++) {
        Entry<String> entry = new Entry<>("Entry " + i);
        LocalDate date = LocalDate.now();
        if (Math.random() < .5) {
            date = date.minusDays((long) (Math.random() * 365));
        } else {
            date = date.plusDays((long) (Math.random() * 365));
        }

        LocalTime start = LocalTime.of((int) (Math.random() * 20), (int) (Math.random() * 30));
        Duration duration = Duration.ofHours((int) (Math.random() * 8));
        LocalTime end = start.plus(duration);
        if (end.isBefore(start)) {
            end = LocalTime.MAX;
        }

        entry.changeStartDate(date);
        entry.changeEndDate(date);
        entry.changeStartTime(start);
        entry.changeEndTime(end);

        if (Math.random() > .9) {
            entry.setFullDay(true);
        }

        entry.setCalendar(calendar[(int) (Math.random() * 7)]);
    }

    source.getCalendars().addAll(calendar);

    monthView = new MonthSheetView();
    monthView.getCalendarSources().add(source);
    monthView.setCellFactory(param -> new MonthSheetView.DetailedDateCell(param.getView(), param.getDate()));

    return monthView;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:48,代碼來源:HelloMonthSheetView.java


注:本文中的java.time.LocalDate.minusDays方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。