List of usage examples for java.time LocalDate minusDays
public LocalDate minusDays(long daysToSubtract)
From source file:com.github.drbookings.model.data.manager.MainManager.java
private void fillMissing() { final List<LocalDate> dates = new ArrayList<>(uiDataMap.keySet()); Collections.sort(dates);/*from ww w . j a v a2 s . c om*/ final Collection<LocalDate> toAdd = new HashSet<>(); LocalDate last = null; for (final LocalDate d : dates) { if (last != null) { if (d.equals(last.plusDays(1))) { // ok } else { toAdd.addAll(new DateRange(last.plusDays(1), d.minusDays(1)).toList()); } } last = d; } for (final LocalDate d : toAdd) { addDateBean(new DateBean(d, this)); } }
From source file:net.resheim.eclipse.timekeeper.ui.Activator.java
/** * Returns a list of weekday names and dates, using the default locale to * determine the first day of the week (Sunday or Monday). * * @param date/* w w w . j a va 2 s . co m*/ * starting date * @return an array with weekday names and dates */ public String[] getHeadings(LocalDate date) { String[] headings = new String[7]; WeekFields weekFields = WeekFields.of(Locale.getDefault()); // Current day in the week int day = date.get(weekFields.dayOfWeek()); // First date of the week LocalDate first = date.minusDays(day - 1); for (int i = 0; i < 7; i++) { headings[i] = formatter.format(first); first = first.plusDays(1); } return headings; }
From source file:mesclasses.view.JourneeController.java
/** * Initializes the controller class.// ww w. j av a 2s .c o m */ @Override public void initialize(URL url, ResourceBundle rb) { LogUtil.logStart(); name = "Journee Ctrl"; super.initialize(url, rb); LOG.debug("Initialisation de " + name); initTabs(); Btns.makeLeft(previousDayBtn); Btns.makeRight(nextDayBtn); Btns.makeLeft(seanceSelect.getBtnLeft()); Btns.makeRight(seanceSelect.getBtnRight()); Btns.makeAdd(addCoursBtn); Btns.makeDelete(remCoursBtn); Btns.tooltip(previousDayBtn, "Jour prcdent"); Btns.tooltip(nextDayBtn, "Jour suivant"); Btns.tooltip(seanceSelect.getBtnLeft(), "Sance prcdente"); Btns.tooltip(seanceSelect.getBtnRight(), "Sance suivante"); Btns.tooltip(addCoursBtn, "Ajouter une sance ponctuelle"); Btns.tooltip(remCoursBtn, "Supprimer la sance ponctuelle"); Btns.tooltip(switchNonActifsBtn, "active/dsactive l'affichage des lves inactifs"); Btns.tooltip(rapportsBtn, "Ouvre la page des rapports trimestriels pour la classe"); Btns.tooltip(punitionsBtn, "Ouvre le suivi des punitions, devoirs et mots pour la classe"); Btns.tooltip(postItBtn, "ouvre le postIt de la classe"); Btns.tooltip(ramasserBtn, "ouvre la fentre des actions faire pour la classe"); currentDate.setDayCellFactory(new TunedDayCellFactory().setAllowSundays(false)); currentDate.setConverter(NodeUtil.DATE_WITH_DAY_NAME); currentDate.valueProperty().addListener(dateListener); displayNonActifs = new SimpleBooleanProperty(false); switchNonActifsBtn.setText("Afficher inactifs"); displayNonActifs.addListener((observable, oldValue, newValue) -> { LOG.debug("Switch actifs/inactifs"); switchNonActifsBtn.setText(displayNonActifs.get() ? "Masquer inactifs" : "Afficher inactifs"); refreshGrid(); }); seanceSelect.addChangeListener((ob, o, n) -> { LOG.debug("seanceSelect changed --> reloading"); loadCurrentSeance(); }); // activation du bouton remCours si besoin rapportsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); punitionsBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); postItBtn.disableProperty().bind(Bindings.isNull(seanceSelect.valueProperty())); // on ne change que la date, le listener sur currentDate se charge du reste LocalDate today = LocalDate.now(); if (today.getDayOfWeek().equals(DayOfWeek.SUNDAY)) { today = today.minusDays(1); } LOG.debug("Initializing with today's date"); currentDate.setValue(today); LogUtil.logEnd(); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private LocalDate getCurrentWeekDate(UserAnonymizedDto userAnonymized) { LocalDate currentDayDate = getCurrentDayDate(userAnonymized); if (currentDayDate.getDayOfWeek() == DayOfWeek.SUNDAY) { // take as the first day of week return currentDayDate; }//from w w w . j a v a 2s. c o m // MONDAY=1, etc. return currentDayDate.minusDays(currentDayDate.getDayOfWeek().getValue()); }
From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java
private LocalDate calculateFirstDayOfWeek(LocalDate date) { WeekFields weekFields = WeekFields.of(Locale.getDefault()); int day = date.get(weekFields.dayOfWeek()); LocalDate firstDayOfWeek = date.minusDays(day - 1); return firstDayOfWeek; }
From source file:com.github.drbookings.model.data.manager.MainManager.java
private BookingBean findBooking(final LocalDate date, final String roomName) throws MatchException { final int maxCount = 100; int count = 0; LocalDate date2 = date; Collection<BookingBean> result2 = null; do {/* www . j a va2s. co m*/ result2 = bookingEntries.get(date2).stream().filter(b -> b.getRoom().getName().equals(roomName)) .filter(b -> !b.isCheckIn()).map(b -> b.getElement()).collect(Collectors.toSet()); if (result2.stream().anyMatch(b -> b.getCleaning() != null)) { if (logger.isDebugEnabled()) { logger.debug("Found entry with cleaning, aborting"); } throw new MatchException("Failed to find matching booking for " + date + " and " + roomName); } result2 = result2.stream().filter(b -> b.getCleaning() == null).collect(Collectors.toSet()); count++; date2 = date2.minusDays(1); } while ((result2 == null || result2.isEmpty()) && count < maxCount); if (count == maxCount) { throw new MatchException("Failed to find matching booking for " + date + " and " + roomName); } if (result2.size() > 1) { throw new MatchException("Found more than one matching booking"); } return result2.iterator().next(); }
From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java
@Test public void TestFindFreeRoomsforReservation() { LocalDate checkin = LocalDate.of(2016, 8, 7); LocalDate checkout = LocalDate.of(2016, 8, 11); LocalDate reservationdate = LocalDate.now(prepareClockMock(now)); Room room1 = setRoom(101, 2, 125, true); Room room2 = setRoom(102, 3, 255, false); Room room3 = setRoom(103, 2, 129, true); Room room4 = setRoom(104, 3, 254, false); Room room5 = setRoom(105, 2, 1278, true); Room room6 = setRoom(106, 3, 252, false); roomManager.createRoom(room1);// w ww . j a v a 2 s . c o m roomManager.createRoom(room2); roomManager.createRoom(room3); roomManager.createRoom(room4); roomManager.createRoom(room5); roomManager.createRoom(room6); Guest guest1 = setGuest("Oleg Bezpalko", "Zagorska", "75899654", "Oleg999@mail"); Guest guest2 = setGuest("Bogdan Voedylo", "Sobranetska", "78965452", "Bogadan777@mail"); Guest guest3 = setGuest("Vasya Voedylo", "Mynaiska", "789999992", "Vasya777@mail"); guestManager.createGuest(guest3); guestManager.createGuest(guest1); guestManager.createGuest(guest2); reservationManager.assignRoomToGuest(guest1, room4, checkin, checkout); reservationManager.assignRoomToGuest(guest2, room6, checkin.plusDays(3), checkout.plusDays(5)); reservationManager.assignRoomToGuest(guest3, room1, checkin.minusDays(5), checkout.minusDays(3)); List<Room> freerooms1 = reservationManager.findFreeRoomsforReservation(checkin, checkout); assertThat("wrong size or rooms created", freerooms1.size(), is(equalTo(3))); List<Room> freerooms2 = reservationManager.findFreeRoomsforReservation(checkin.plusDays(2), checkout.minusDays(2)); assertThat("wrong size or rooms created", freerooms2.size(), is(equalTo(5))); List<Room> freerooms3 = reservationManager.findFreeRoomsforReservation(checkin, checkin); assertThat("wrong size or rooms created", freerooms3.size(), is(equalTo(4))); }
From source file:de.lgblaumeiser.ptm.rest.BookingControllerTest.java
@Test public void testRoundtripCreateAndRetrieveBooking() throws Exception { ActivityRestController.ActivityBody data = new ActivityRestController.ActivityBody(); data.activityName = "MyTestActivity"; data.bookingNumber = "0815"; mockMvc.perform(/* w w w .ja v a2 s. com*/ post("/activities").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(data))) .andDo(print()).andExpect(status().isCreated()); LocalDate date = LocalDate.now(); String dateString = date.format(ISO_LOCAL_DATE); BookingRestController.BookingBody booking = new BookingRestController.BookingBody(); booking.activityId = "1"; booking.user = "TestUser"; booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME); booking.comment = ""; mockMvc.perform(post("/bookings/" + dateString).contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated()); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString(dateString))); mockMvc.perform(get("/bookings/" + dateString)).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))); mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))); booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME); mockMvc.perform(post("/bookings/" + dateString + "/1").contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isOk()); mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("starttime"))) .andExpect(content().string(containsString("endtime"))); LocalDate date2 = date.minusDays(1); String dateString2 = date2.format(ISO_LOCAL_DATE); booking = new BookingRestController.BookingBody(); booking.activityId = "1"; booking.user = "TestUser"; booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME); booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME); booking.comment = "Test Comment"; mockMvc.perform(post("/bookings/" + dateString2).contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated()); mockMvc.perform(get("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("MyTestActivity"))) .andExpect(content().string(containsString("0815"))) .andExpect(content().string(containsString("TestUser"))) .andExpect(content().string(containsString("Test Comment"))) .andExpect(content().string(containsString("starttime"))) .andExpect(content().string(containsString("endtime"))); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString(dateString))) .andExpect(content().string(containsString(dateString2))); mockMvc.perform(delete("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk()); mockMvc.perform(delete("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk()); mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk()) .andExpect(content().string(containsString("[]"))); }
From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java
@Override public void createPartControl(Composite parent) { FormToolkit ft = new FormToolkit(parent.getDisplay()); ScrolledComposite root = new ScrolledComposite(parent, SWT.V_SCROLL); ft.adapt(root);/*from w ww . ja v a 2 s . co m*/ GridLayout layout = new GridLayout(); root.setLayout(layout); root.setExpandHorizontal(true); root.setExpandVertical(true); Composite main = ft.createComposite(root); ft.adapt(main); root.setContent(main); GridLayout layout2 = new GridLayout(3, false); layout2.horizontalSpacing = 0; main.setLayout(layout2); dateTimeLabel = new Text(main, SWT.NONE); GridData gdLabel = new GridData(); gdLabel.verticalIndent = 3; gdLabel.verticalAlignment = SWT.BEGINNING; dateTimeLabel.setLayoutData(gdLabel); dateChooser = new DateTime(main, SWT.DROP_DOWN | SWT.DATE | SWT.LONG); GridData gdChooser = new GridData(); gdChooser.verticalAlignment = SWT.BEGINNING; dateChooser.setLayoutData(gdChooser); ft.adapt(dateChooser); dateChooser.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { // Determine the first date of the week LocalDate date = LocalDate.of(dateChooser.getYear(), dateChooser.getMonth() + 1, dateChooser.getDay()); contentProvider.setFirstDayOfWeek(calculateFirstDayOfWeek(date)); viewer.setInput(this); } }); statusLabel = new Text(main, SWT.NONE); GridData gdStatusLabel = new GridData(); gdStatusLabel.grabExcessHorizontalSpace = true; gdStatusLabel.horizontalAlignment = SWT.FILL; gdStatusLabel.verticalIndent = 3; gdStatusLabel.verticalAlignment = SWT.BEGINNING; statusLabel.setLayoutData(gdStatusLabel); viewer = new TreeViewer(main, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); // Make the tree view provide selections getSite().setSelectionProvider(viewer); contentProvider = new ViewContentProvider(); viewer.setContentProvider(contentProvider); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData.horizontalSpan = 3; viewer.getControl().setLayoutData(layoutData); createTitleColumn(); for (int i = 0; i < 7; i++) { createTimeColumn(i); } Tree tree = viewer.getTree(); viewer.setComparator(new ViewerComparatorExtension()); tree.setHeaderVisible(true); tree.setLinesVisible(true); // Adjust column width when view is resized root.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle area = root.getClientArea(); int width = area.width - 2 * tree.getBorderWidth(); Point vBarSize = tree.getVerticalBar().getSize(); width -= vBarSize.x; TreeColumn[] columns = tree.getColumns(); int cwidth = 0; for (int i = 1; i < columns.length; i++) { columns[i].pack(); if (columns[i].getWidth() < 50) { columns[i].setWidth(50); } cwidth += columns[i].getWidth(); } tree.getColumns()[0].setWidth(width - cwidth); } }); // Determine the first date of the week LocalDate date = LocalDate.now(); WeekFields weekFields = WeekFields.of(Locale.getDefault()); int day = date.get(weekFields.dayOfWeek()); contentProvider.setFirstDayOfWeek(date.minusDays(day - 1)); makeActions(); hookContextMenu(); hookDoubleClickAction(); contributeToActionBars(); taskListener = new TaskListener(); TasksUiPlugin.getTaskActivityManager().addActivationListener(taskListener); TasksUiPlugin.getTaskList().addChangeListener(taskListener); viewer.setInput(getViewSite()); // Force a redraw so content is visible root.pack(); installStatusUpdater(); }
From source file:org.apache.tez.dag.history.logging.proto.DagManifesFileScanner.java
private boolean loadMore() throws IOException { LocalDateTime now = manifestLogger.getNow(); LocalDate today = now.toLocalDate(); String todayDir = manifestLogger.getDirForDate(today); loadNewFiles(todayDir);//from www .j a va 2s. c om while (newFiles.isEmpty()) { if (now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond() < syncTime) { // We are in the delay window for today, do not advance date if we are moving from // yesterday. if (scanDir.equals(manifestLogger.getDirForDate(today.minusDays(1)))) { return false; } } String nextDir = manifestLogger.getNextDirectory(scanDir); if (nextDir == null) { return false; } scanDir = nextDir; offsets = new HashMap<>(); retryCount = new HashMap<>(); loadNewFiles(todayDir); } return true; }