List of usage examples for org.joda.time MutableDateTime getDayOfYear
public int getDayOfYear()
From source file:com.foundationdb.server.types.mcompat.mfuncs.MWeek.java
License:Open Source License
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) { cal.setYear(yr);//from ww w. ja v a 2 s .c o m cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); int week = cal.getDayOfYear() - (firstD + 1); // Sun/Mon if (firstD < 4) { if (week < 0) return modes[lowestVal].getWeek(cal, yr - 1, 12, 31); else return week / 7 + 1; } else { if (week < 0) return 1; else return week / 7 + 2; } }
From source file:com.foundationdb.server.types.mcompat.mfuncs.MWeek.java
License:Open Source License
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) { cal.setYear(yr);//from w w w .j a v a 2 s . c o m cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); int dayOfYear = cal.getDayOfYear(); if (dayOfYear < firstD) return modes[lowestVal].getWeek(cal, yr - 1, 12, 31); else return (dayOfYear - firstD) / 7 + 1; }
From source file:com.foundationdb.server.types.mcompat.mfuncs.MYearWeek.java
License:Open Source License
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) { cal.setYear(yr);//from w w w .j a v a 2s . c o m cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); int week = cal.getDayOfYear() - (firstD + 1); // Sun/Mon if (firstD < 4) { if (week < 0) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31); else return yr * 100 + week / 7 + 1; } else { if (week < 0) return yr * 100 + 1; else return yr * 100 + week / 7 + 2; } }
From source file:com.foundationdb.server.types.mcompat.mfuncs.MYearWeek.java
License:Open Source License
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal) { cal.setYear(yr);//from w w w .j av a 2 s. co m cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); int dayOfYear = cal.getDayOfYear(); if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31); else return yr * 100 + (dayOfYear - firstD) / 7 + 1; }
From source file:com.foundationdb.server.types.texpressions.DateTimeField.java
License:Open Source License
/** * to be used in V, v, U and u// www. ja v a 2s . c om * @param cal * @param yr * @param mo * @param da * @param firstDay * @param lowestIs0: whether the lowest value could be zero or not * @return the week for this date, if the lowest value is not supposed to be zero, then it returns that * the number of the last week in the previous year */ private static int getWeek(MutableDateTime cal, int yr, int mo, int da, int firstDay, boolean lowestIs0) { cal.setYear(yr); cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); int dayOfYear = cal.getDayOfYear(); int result; if (dayOfYear < firstD) result = (lowestIs0 ? 0 : getWeek(cal, yr - 1, 12, 31, firstDay, lowestIs0)); else result = (dayOfYear - firstD) / 7 + 1; // reset cal cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); return result; }
From source file:com.tmathmeyer.sentinel.ui.navigation.MiniMonth.java
License:Open Source License
public MiniMonth(DateTime time, final MiniCalendarHostIface mc, boolean monthOnly) { this.setLayout(new GridLayout(7, 7)); MutableDateTime prevMonth = new MutableDateTime(time); prevMonth.setDayOfMonth(1);// w w w . j a v a 2 s . c o m prevMonth.addMonths(-1); // What is prevMonth for? String[] dayLabel = { "S", "M", "T", "W", "R", "F", "S" }; MouseListener monthChanger = new MouseListener() { @Override public void mouseClicked(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { DayLabel d = (DayLabel) (me.getSource()); if (!(d instanceof DescriptiveDayLabel)) { mc.display(d.getMonth()); } } }; MutableDateTime referenceDay = new MutableDateTime(time); // reset to the first of the month at midnight, then find Sunday referenceDay.setDayOfMonth(1); referenceDay.setMillisOfDay(0); int first = referenceDay.getDayOfWeek(); referenceDay.addDays(-first); boolean flipFlop = false; // add day labels for (int i = 0; i < 7; i++) { DayLabel day = new DescriptiveDayLabel(dayLabel[i], time); day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6); add(day); day.addMouseListener(monthChanger); } // generate days, 6*7 covers all possible months, so we just loop // through and add each day for (int i = 0; i < (6 * 7); i++) { DayLabel day; if (monthOnly || MainPanel.getInstance().getView() == ViewSize.Month) { if (referenceDay.getDayOfMonth() == 1) flipFlop ^= true; // flops the flip flop flappity flip } else if (MainPanel.getInstance().getView() == ViewSize.Day) flipFlop = referenceDay.getDayOfYear() == time.getDayOfYear() && referenceDay.getYear() == time.getYear(); else if (MainPanel.getInstance().getView() == ViewSize.Week) { if (Months.getWeekStart(time).getMonthOfYear() == 12 && Months.getWeekStart(time).getDayOfMonth() >= 26) // Exception // case // for // weeks // between // years flipFlop = time.getMonthOfYear() == 12 ? i >= 35 : i <= 6; else flipFlop = referenceDay.getDayOfYear() >= Months.getWeekStart(time).getDayOfYear() && referenceDay.getDayOfYear() <= Months.getWeekStart(time).getDayOfYear() + 6; } if (flipFlop) day = new ActiveDayLabel(referenceDay.toDateTime()); else day = new InactiveDayLabel(referenceDay.toDateTime()); day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6); add(day); day.addMouseListener(monthChanger); referenceDay.addDays(1); // go to next day } }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
/** * Adds or deletes a displayable from the days its occupies * // w ww. j a va 2s .co m * @param e * @param add */ protected void traverseDisplayable(Displayable e, Lambda<MonthDay> func) { // get and normalize the range of the disp Interval ival = e.getInterval(); MutableDateTime startDay = new MutableDateTime(ival.getStart()); MutableDateTime endDay = new MutableDateTime(ival.getEnd()); endDay.setMillisOfDay(0); startDay.setMillisOfDay(0); // bound it inside this visible month if (startDay.isBefore(firstOnMonth)) startDay = new MutableDateTime(firstOnMonth); if (endDay.isAfter(lastOnMonth)) endDay = new MutableDateTime(lastOnMonth); // go from start to end and add it to all the days in the way while (!endDay.isBefore(startDay)) { MonthDay md = this.days.get(startDay.getDayOfYear()); if (md != null) func.call(md); startDay.addDays(1); } }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
/** * Fill calendar with month in referenceDay * //from w ww. ja v a 2s . c om * @param referenceDay what month should we display */ protected void generateDays(MutableDateTime referenceDay) { // reset to the first of the month at midnight, then find Sunday referenceDay.setDayOfMonth(1); referenceDay.setMillisOfDay(0); int first = (referenceDay.getDayOfWeek() % 7); int daysInView = first + referenceDay.dayOfMonth().getMaximumValue(); int weeks = (int) Math.ceil(daysInView / 7.0); inside.setLayout(new java.awt.GridLayout(weeks, 7)); referenceDay.addDays(-first); firstOnMonth = new DateTime(referenceDay); // remove all old days inside.removeAll(); DateTime from = referenceDay.toDateTime(); // generate days, weeks*7 covers all possible months, so we just loop // through and add each day for (int i = 0; i < (weeks * 7); i++) { MonthDay md = new MonthDay(referenceDay.toDateTime(), getMarker(referenceDay), this); inside.add(md); md.reBorder(i < 7, (i % 7) == 0, i >= (weeks - 1) * 7); this.days.put(referenceDay.getDayOfYear(), md); referenceDay.addDays(1); // go to next day } referenceDay.addDays(-1);// go back one to counteract last add one lastOnMonth = new DateTime(referenceDay); setDisplayables(getVisibleItems(from, referenceDay.toDateTime())); monthLabel.setText(this.getTime().toString(Months.monthLblFormat)); // notify mini-calendar to change mainPanel.miniMove(time); // repaint when changed mainPanel.revalidate(); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Selects an event's corresponding Displayable * //from w ww .j a va 2s. c o m * @param on Event being selected * @param setTo Displayable of Event being selected */ private void selectEvents(Event on, Displayable setTo) { // TODO: refactor this pattern DayPanel mLouvreTour; MutableDateTime startDay = new MutableDateTime(on.getStart()); MutableDateTime endDay = new MutableDateTime(on.getEnd()); endDay.setMillisOfDay(0); endDay.addDays(1); endDay.addMillis(-1); startDay.setMillisOfDay(0); Interval eventLength = new Interval(startDay, endDay); if (setTo == null || eventLength.toDuration().getStandardHours() > 24) { for (WeekMultidayEventItem multidayItem : multidayItemList) { if (setTo != null && multidayItem.getEvent().getUuid().equals(((Event) on).getUuid())) multidayItem.setSelected(true); else multidayItem.setSelected(false); } return; } // TODO: can be simplified now that multiday events are handled // elsewhere int index = 0; for (int i = 0; i < 7; i++) { if (startDay.getDayOfYear() == daysOfWeekArray[i].getDisplayDate().getDayOfYear()) { index = i; break; } } while (index < 7 && !endDay.isBefore(daysOfWeekArray[index].getDisplayDate())) { mLouvreTour = daysOfWeekArray[index]; try { mLouvreTour.select(setTo); } catch (NullPointerException ex) { // silently ignore as this is apparently not in the view } index++; } }
From source file:com.tmathmeyer.sentinel.ui.views.year.YearCalendar.java
License:Open Source License
/** * gets the drawn year/* www .java2 s . c om*/ * * @param start the date time that starts the series. * @return the jpanel that contains the colored days and the S/M/T/W/R/F/S * labels */ private JPanel getFourMonthGrid(MutableDateTime start) { int gridHeight = 19; int gridWidth = 7; JPanel p = new JPanel(); p.setLayout(new GridLayout(gridHeight, gridWidth)); String[] days = { "S", "M", "T", "W", "R", "F", "S" }; for (int i = 0; i < 7; i++) { JLabel header = new JLabel(days[i]); header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Colors.BORDER)); header.setHorizontalAlignment(SwingConstants.CENTER); header.setFont(new Font("DejaVu Sans", Font.ITALIC, 12)); p.add(header); } for (int j = 0; j < 18 * 7; j++) { Color dayBackground = start.getMonthOfYear() % 2 == 0 ? Colors.TABLE_BACKGROUND : Colors.TABLE_GRAY_HEADER; Integer eventCount = events.get(start.getDayOfYear()); eventCount = eventCount == null ? 0 : eventCount; YearlyDayHolder day = new YearlyDayHolder(start.toDateTime(), dayBackground); MutableDateTime today = new MutableDateTime(DateTime.now()); today.setMillisOfDay(0); MutableDateTime checking = new MutableDateTime(start); start.setMillisOfDay(0); if (checking.toDateTime().isEqual(today)) { day.setBackground(Colors.SELECTED_BACKGROUND); day.setForeground(Colors.SELECTED_TEXT); } JLabel dayLabel = new JLabel(start.getDayOfMonth() + ""); dayLabel.setHorizontalAlignment(SwingConstants.CENTER); day.setLayout(new GridLayout(1, 1)); day.add(dayLabel); day.setBorder( BorderFactory.createMatteBorder(0, start.getDayOfWeek() % 7 == 0 ? 1 : 0, 1, 1, Colors.BORDER)); day.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent me) { YearlyDayHolder event = (YearlyDayHolder) (me.getSource()); MainPanel.getInstance().miniMove(event.getDateTime()); MainPanel.getInstance().viewDay(); } @Override public void mouseEntered(MouseEvent me) { // this is just a demo of what it can do } @Override public void mouseExited(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { // TODO: something? maybe nothing? have to decide with // team/steakholders } @Override public void mouseReleased(MouseEvent me) { YearlyDayHolder event = (YearlyDayHolder) (me.getSource()); MainPanel.getInstance().miniMove(event.getDateTime()); } }); p.add(day); start.addDays(1); } int width = 280; int height = 570; p.setMinimumSize(new Dimension(0, height - 150)); p.setPreferredSize(new Dimension(width, height)); p.setMaximumSize(new Dimension(width + 350, height + 150)); return p; }