List of usage examples for java.time ZonedDateTime minus
@Override public ZonedDateTime minus(long amountToSubtract, TemporalUnit unit)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.minus(12, ChronoUnit.DAYS); System.out.println(n);//from w w w .j av a 2s .c om }
From source file:com.yahoo.egads.models.tsmm.OlympicModel2.java
/** * Sets the index into the DataSequence object for each window along with * calculating the window times. The index or timestamp for each window will * be one of the following: - -1 to show that there isn't any data for that * window - An index where the timestamp is the exact value of the seek time * - An index where the timestamp is a value greater than the seek time * //from w w w . j a v a2s. co m * @param data * A non-null and non-empty data sequence object to read from. * @throws IllegalArgumentException * if the data object was null or empty. */ @VisibleForTesting void initializeIndices(final DataSequence data, final long start) { if (data == null || data.size() < 1) { throw new IllegalArgumentException("DataSequence cannot be null or empty."); } final ZonedDateTime base = Instant.ofEpochSecond(start).atZone(zone); for (int i = 0; i < pastWindows; i++) { final ZonedDateTime seek = base.minus((windowDistanceInterval * (pastWindows - i)), windowDistanceIntervalUnits); final long seek_time = seek.toEpochSecond(); // cut down on iterations by dividing the data idx int idx = data.size() / (pastWindows - i); if (idx >= data.size()) { idx = data.size() - 1; } if (data.get(idx).time == seek_time) { // woot, found it! } else if (data.get(idx).time < seek_time) { while (idx < data.size() && data.get(idx).time < seek_time) { idx++; } } else { while (idx > 0 && data.get(idx - 1).time >= seek_time) { idx--; } } // reset to avoid OOB exceptions. if (idx >= data.size()) { idx = -1; } windowTimes[i] = seek; indices[i] = idx; if (LOG.isDebugEnabled()) { LOG.debug("Initializing index: " + i + " to " + idx + " at " + seek); } } }
From source file:com.example.app.profile.ui.user.ProfileMembershipManagement.java
void doDatesEdit(@Nullable Membership membership) { if (membership == null) return;// www .j av a2s. c om final MembershipType membershipType = membership.getMembershipType(); assert membershipType != null; Label heading = new Label(createText(EDIT_DATES_UI_HEADING_FORMAT(), membership.getUser().getName(), membershipType.getName())); heading.setHTMLElement(HTMLElement.h3); MessageContainer messages = new MessageContainer(35_000L); PushButton saveButton = CommonActions.SAVE.push(); PushButton cancelButton = CommonActions.CANCEL.push(); RelativeOffsetRange range = new RelativeOffsetRange(5, 2); CalendarValueEditor startDateEditor = new CalendarValueEditor(START_DATE(), membership.getStartDate(), range); CalendarValueEditor endDateEditor = new CalendarValueEditor(END_DATE(), membership.getEndDate(), range); Container ui = of("edit-membership prop-wrapper prop-editor", messages, heading, of("prop-body", startDateEditor, endDateEditor), of("actions persistence-actions bottom", saveButton, cancelButton)); ActionListener closer = ev -> ui.close(); saveButton.addActionListener(ev -> { if (((Supplier<Boolean>) () -> { final Date startDate = startDateEditor.commitValue(); final Date endDate = endDateEditor.commitValue(); membership.setStartDate( convertForPersistence(toZonedDateTime(startDate, getSession().getTimeZone()))); ZonedDateTime endDateTime = toZonedDateTime(endDate, getSession().getTimeZone()); membership.setEndDate( convertForPersistence(endDateTime != null ? endDateTime.minus(1, ChronoUnit.DAYS) : null)); if (startDate != null && endDate != null && startDate.after(endDate)) { messages.sendNotification(NotificationImpl.error(ERROR_START_DATE_AFTER_END_DATE())); return false; } return true; }).get()) { closer.actionPerformed(ev); showHideConstraints(); } }); cancelButton.addActionListener(closer); getHistory().add(new HistoryElement(ui)); navigateBackOnClose(ui); }