List of usage examples for org.joda.time MutableDateTime getYear
public int getYear()
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);/*from www. j a v a2s. 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.week.WeekCalendar.java
License:Open Source License
/** * Generates the day displays in the week panel *//* w ww. j av a 2s. c o m*/ private void generateDay() { // clear out the specifics smithsonian.removeAll(); headerBox.removeAll(); // add the day grid back in hourLabels = new DayGridLabel(); smithsonian.add(hourLabels, "cell 0 0,grow"); MutableDateTime increment = new MutableDateTime(weekStartTime); increment.setMillisOfDay(0); DateTime now = DateTime.now().withMillisOfDay(0); displayableList = getVisibleDisplayables(); for (int i = 0; i < 7; i++) { // add day views to the day grid this.daysOfWeekArray[i] = new DayPanel(true, this); this.daysOfWeekArray[i].setEvents( getDisplayablesInInterval(increment.toDateTime(), increment.toDateTime().plusDays(1)), increment.toDateTime()); this.daysOfWeekArray[i] .setBorder(BorderFactory.createMatteBorder(1, 0, 1, i == 6 ? 0 : 1, Colors.BORDER)); this.smithsonian.add(this.daysOfWeekArray[i], "cell " + (i + 1) + " 0,grow"); // add day titles to the title grid dayHeaders[i].setText(increment.toDateTime().toString(dayTitleFmt)); dayHeaders[i] .setFont(dayHeaders[i].getFont().deriveFont(increment.isEqual(now) ? Font.BOLD : Font.PLAIN)); increment.addDays(1); } // populate and set up the multiDayEventGrid populateMultidayEventGrid(); // setup week title increment.addDays(-1); // smart titles if (weekStartTime.getYear() != increment.getYear()) weekTitle .setText(weekStartTime.toString(monthDayYearFmt) + " - " + increment.toString(monthDayYearFmt)); else if (weekStartTime.getMonthOfYear() != increment.getMonthOfYear()) weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(monthDayYearFmt)); else weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(dayYearFmt)); // notify mini-calendar to change mainPanel.miniMove(time); }
From source file:com.tmathmeyer.sentinel.ui.views.year.YearCalendar.java
License:Open Source License
/** * /*from w w w.j a va 2 s .c om*/ * @param mdt a mutable date time on which to start the calendar. this can * be used to make the dynamic month scrolling work if needed. */ private void drawCalendar(MutableDateTime mdt) { this.removeAll(); mdt = this.calendarStart = getStartOfYearCalendar(mdt.toDateTime()); MutableDateTime upperBound = mdt.copy(); upperBound.addDays(378); getVisibleEvents(mdt.toDateTime(), upperBound.toDateTime()); MutableDateTime yearDate = mdt.copy(); yearDate.addDays(20); int year = yearDate.getYear(); JLabel title = new JLabel(year + ""); title.setHorizontalAlignment(SwingConstants.CENTER); title.setFont(new Font("DejaVu Sans", Font.BOLD, 25)); JPanel content = new JPanel(); this.add(title, BorderLayout.NORTH); this.add(content, BorderLayout.CENTER); MutableDateTime monthCounter = mdt.copy(); content.setLayout(new BoxLayout(content, 0)); for (int i = 0; i < 3; i++) { content.add(new Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(65566, 0))); content.add(getFourMonthLabel(monthCounter.copy())); content.add(getFourMonthGrid(mdt.copy())); content.add(new Box.Filler(new Dimension(0, 0), new Dimension(0, 0), new Dimension(65566, 0))); mdt.addDays(18 * 7); monthCounter.addMonths(4); } }
From source file:edu.wpi.cs.wpisuitetng.modules.cal.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);/*from ww w . java 2s .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:jais.messages.StaticAndVoyageRelatedData.java
License:Apache License
/** * * @return//from www . ja v a 2 s .c o m */ public MutableDateTime getETA() { StringBuilder eta = new StringBuilder(); MutableDateTime dt = MutableDateTime.now(); int year = dt.getYear(); int month = dt.getMonthOfYear(); if (_month > 0) { // properly formatted month if (_month < 10) { eta.append("0").append(_month); } else if (_month > 12) { eta.append("12"); _month = 12; // use this to validate the days later } else { eta.append(_month); } eta.append("/"); // assume next year if (_month < month) { year++; } // prepend datetime string with YYYY/ eta.insert(0, year).insert(4, "/"); // recreate the Calendar object based on the validated month dt = new MutableDateTime(year, _month, 1, 0, 0, 0, 0, DateTimeZone.UTC); // Get the number of days in that month int daysInMonth = dt.monthOfYear().getMaximumValue(); // properly formatted day if (_day < 1) { eta.append("01"); } else if (_day < 10) { eta.append("0").append(_day); } else if (_day >= daysInMonth) { eta.append(daysInMonth); } else { eta.append(_day); } eta.append(" "); // properly formatted hour if (_hour < 1) { eta.append("00"); } else if (_hour < 10) { eta.append("0").append(_hour); } else if (_hour >= 24) { eta.append(00); } else { eta.append(_hour); } eta.append(":"); // properly formatted minute if (_minute < 1 || _minute > 59) { eta.append("00"); } else if (_minute < 10) { eta.append("0").append(_minute); } else { eta.append(_minute); } } else { // default to epoch if month is invalid eta.append("1970/01/01 00:00"); } try { dt = MutableDateTime.parse(eta.toString(), ETA_FORMATTER); } catch (Exception e) { LOG.warn("Invalid ETA, setting to epoch"); dt = MutableDateTime.parse("1970/01/01 00:00", ETA_FORMATTER); } return dt; }
From source file:org.elasticsearch.common.joda.DateMathParser.java
License:Apache License
private long parseRoundCeilStringValue(String value) { try {/*from w w w . j a v a2 s. c o m*/ // we create a date time for inclusive upper range, we "include" by default the day level data // so something like 2011-01-01 will include the full first day of 2011. // we also use 1970-01-01 as the base for it so we can handle searches like 10:12:55 (just time) // since when we index those, the base is 1970-01-01 MutableDateTime dateTime = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); int location = dateTimeFormatter.parser().parseInto(dateTime, value, 0); // if we parsed all the string value, we are good if (location == value.length()) { return dateTime.getMillis(); } // if we did not manage to parse, or the year is really high year which is unreasonable // see if its a number if (location <= 0 || dateTime.getYear() > 5000) { try { long time = Long.parseLong(value); return timeUnit.toMillis(time); } catch (NumberFormatException e1) { throw new ElasticsearchParseException( "failed to parse date field [" + value + "], tried both date format [" + dateTimeFormatter.format() + "], and timestamp number"); } } return dateTime.getMillis(); } catch (RuntimeException e) { try { long time = Long.parseLong(value); return timeUnit.toMillis(time); } catch (NumberFormatException e1) { throw new ElasticsearchParseException("failed to parse date field [" + value + "], tried both date format [" + dateTimeFormatter.format() + "], and timestamp number", e); } } }
From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java
License:Open Source License
@Override public XMLGregorianCalendar convertToDatum(Object timestamp) { if (timestamp == null) { return null; }/*from w w w. j a v a 2 s . c o m*/ long timestampMillis; if (timestamp instanceof Long) { timestampMillis = ((Long) timestamp).longValue(); } else if (timestamp instanceof Date) { timestampMillis = ((Date) timestamp).getTime(); } else { throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp); } MutableDateTime dateTime = new MutableDateTime(); dateTime.setMillis(timestampMillis); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }