List of usage examples for java.time LocalDate get
@Override public int get(TemporalField field)
From source file:Main.java
/** * Returns the current quarter of the given date * // w w w. ja v a 2 s . c o m * @return int (0 .. 3) * @param cal * Given date, cannot be null */ public static int getQuarter(LocalDate cal) { int month = cal.get(ChronoField.MONTH_OF_YEAR); switch (Month.of(month)) { case JANUARY: case FEBRUARY: case MARCH: default: return 0; case APRIL: case MAY: case JUNE: return 1; case JULY: case AUGUST: case SEPTEMBER: return 2; case OCTOBER: case NOVEMBER: case DECEMBER: return 3; } }
From source file:Main.java
/** * This method checks whether the given date object is representing a date at * the weekend (Saturday or Sunday)/* w w w . j a va 2 s . c o m*/ * * @param date * Date to check, cannot be null * @return TRUE is Saturday or Sunday */ public static boolean isWeekend(LocalDate date) { DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK)); switch (dayOfWeek) { case SATURDAY: case SUNDAY: return true; default: return false; } }
From source file:Main.java
/** * The methods calculates the previous working day. It only recognize Saturday * and Sunday as non -working days./*from www . j a v a 2s. co m*/ * * @param date * Date as starting point for the calculation, cannot be null * @return The previous working day */ public static LocalDate getPreviousWorkingDay(LocalDate date) { DayOfWeek dayOfWeek = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK)); switch (dayOfWeek) { case MONDAY: return date.minus(3, ChronoUnit.DAYS); case SUNDAY: return date.minus(2, ChronoUnit.DAYS); default: return date.minus(1, ChronoUnit.DAYS); } }
From source file:mesclasses.util.NodeUtil.java
public static int getWeekNumber(LocalDate date) { WeekFields wf = WeekFields.of(Locale.FRANCE); return date.get(wf.weekOfWeekBasedYear()); }
From source file:Main.java
/** * Calculates the number of quarters between two given dates * /*from www. j ava 2 s .c o m*/ * @return Number of quarters * @param date1 * First given date cannot be null * @param date2 * Second given date cannot be null */ public static int getQuartersBetweenDates(LocalDate date1, LocalDate date2) { LocalDate beginn = null; LocalDate end = null; if (date1.isBefore(date2)) { beginn = date1; end = date2; } else { beginn = date2; end = date1; } int quarters = getQuarter(end) - getQuarter(beginn); int years = end.get(ChronoField.YEAR) - beginn.get(ChronoField.YEAR); quarters += years * 4; return Math.abs(quarters); }
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// www . ja va 2s . com * 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: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: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 ww w .ja v a 2 s .c o 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(); }