List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisCompute.java
License:Open Source License
private Period computeOffset(IntervalleObject presentInterval, IntervalleObject pastInterval, AxisValues joinAxis) throws ScopeException { // it is better to compare on the lower bound because alignment on the // end of month is not accurate Object present = presentInterval.getLowerBound(); Object past = pastInterval.getLowerBound(); ///* w w w .j av a 2s.c o m*/ IDomain image = joinAxis.getAxis().getDefinition().getImageDomain(); PeriodType type = computePeriodType(image); // if (present instanceof Date && past instanceof Date) { Period presentPeriod = new Period(new LocalDate(((Date) presentInterval.getLowerBound()).getTime()), new LocalDate(((Date) presentInterval.getUpperBound()).getTime()).plusDays(1), type); Period pastPeriod = new Period(new LocalDate(((Date) pastInterval.getLowerBound()).getTime()), new LocalDate(((Date) pastInterval.getUpperBound()).getTime()).plusDays(1), type); Date pastDate = (Date) past; DateTime dt = new DateTime(pastDate); if (image.isInstanceOf(IDomain.YEARLY)) { if (presentPeriod.getYears() > pastPeriod.getYears()) { // e.g. presentPeriod of 365 days -> // presentPeriod.getYears=1 && past year of 366 days -> // pastPeriod.getYears=0 DateTime newDT = new DateTime(dt.getYear(), 1, 1, 0, 0); pastDate = newDT.toDate(); } else { if (dt.getDayOfYear() != 1) { // e.g present period of 366 days -> past date at dec 31 DateTime newDT = new DateTime(dt.getYear() + 1, 1, 1, 0, 0); pastDate = newDT.toDate(); } } } else if (image.isInstanceOf(IDomain.QUATERLY) || image.isInstanceOf(IDomain.MONTHLY)) { if (presentPeriod.getMonths() > pastPeriod.getMonths()) { // e.g present period of 28 days(February) -> // pastPeriod.getMonths() = 0 (January has 31 days) DateTime newDT = new DateTime(dt.getYear(), dt.getMonthOfYear(), 1, 0, 0); pastDate = newDT.toDate(); } else { if (dt.getDayOfMonth() != 1) { // e.g. present period of 31 day(March) pastDate = Feb 6 if (dt.getMonthOfYear() == 12) { DateTime newDT = new DateTime(dt.getYear() + 1, 1, 1, 0, 0); pastDate = newDT.toDate(); } else { DateTime newDT = new DateTime(dt.getYear(), dt.getMonthOfYear() + 1, 1, 0, 0); pastDate = newDT.toDate(); } } } } else { // daily, keep Date as it is } return new Period(new LocalDate((pastDate).getTime()), new LocalDate(((Date) present).getTime()), type); } else { return null; } }
From source file:com.tech.auju.implementation.GudangImpl.java
/** * Get today date.// w ww .j a v a2 s . co m * @return Today date. */ private Date getTime() { DateTime dt = new DateTime(); int d = dt.getDayOfMonth(); int m = dt.getMonthOfYear(); int y = dt.getYear(); System.out.println("GETTIME : " + y + m + d); return new Date(y - 1900, m, d); }
From source file:com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution.java
License:Apache License
@Override public void setStartTime(DateTime startTime) { this.startTime = startTime; if (startTime != null) { this.startYear = startTime.getYear(); this.startMonth = startTime.getMonthOfYear(); this.startDay = startTime.getDayOfMonth(); }/*from ww w . j a va 2s. co m*/ }
From source file:com.thinkbiganalytics.metadata.jpa.jobrepo.job.JpaBatchJobExecution.java
License:Apache License
@Override public void setEndTime(DateTime endTime) { this.endTime = endTime; if (endTime != null) { this.endYear = endTime.getYear(); this.endMonth = endTime.getMonthOfYear(); this.endDay = endTime.getDayOfMonth(); }// ww w . j a va 2 s.com }
From source file:com.tkmtwo.sarapi.support.ValueUtil.java
License:Apache License
public static DateInfo toDateInfo(DateTime dt) { if (dt == null) { return null; }/*from ww w . j a v a 2s . c o m*/ return new DateInfo(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth()); }
From source file:com.tmathmeyer.sentinel.models.data.Commitment.java
License:Open Source License
@Override public String getFormattedDateRange() { DateTime s = new DateTime(this.duedate); StringBuilder timeFormat = new StringBuilder().append(s.monthOfYear().getAsShortText()).append(", ") .append(Months.getDescriptiveNumber(s.getDayOfMonth())); return timeFormat.toString(); }
From source file:com.tmathmeyer.sentinel.models.data.Event.java
License:Open Source License
@Override public String getFormattedDateRange() { if (this.isMultiDayEvent()) { DateTime s = new DateTime(this.start); DateTime e = new DateTime(this.end); StringBuilder timeFormat = new StringBuilder().append(s.monthOfYear().getAsShortText()).append(", ") .append(Months.getDescriptiveNumber(s.getDayOfMonth())).append(" - ") .append(e.monthOfYear().getAsShortText()).append(", ") .append(Months.getDescriptiveNumber(e.getDayOfMonth())); return timeFormat.toString(); } else {/*from www . j av a 2 s. co m*/ DateTime s = new DateTime(this.start); StringBuilder timeFormat = new StringBuilder().append(s.monthOfYear().getAsShortText()).append(", ") .append(Months.getDescriptiveNumber(s.getDayOfMonth())); return timeFormat.toString(); } }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthDay.java
License:Open Source License
public MonthDay(DateTime initDay, DayStyle style, final MonthCalendar parent) { this.day = initDay; this.style = style; Color grayit = Colors.TABLE_GRAY_HEADER, textit = Colors.TABLE_TEXT, bg = Colors.TABLE_BACKGROUND; switch (style) { case Normal:/*from w w w. j a v a2 s. com*/ grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; case OutOfMonth: grayit = bg; break; case Today: grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; default: throw new IllegalStateException("DayStyle is not a valid DayStyle!"); } setBackground(bg); setForeground(textit); borderTop = grayit.equals(bg); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); header.setBackground(grayit); header.setForeground(textit); header.setFont(new java.awt.Font("DejaVu Sans", style == DayStyle.Today ? Font.BOLD : Font.PLAIN, 12)); header.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); header.setText(Integer.toString(initDay.getDayOfMonth())); header.setAutoscrolls(true); header.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); header.setMaximumSize(new java.awt.Dimension(10000, 17)); header.setOpaque(true); if (style == DayStyle.Today) { Font font = header.getFont(); Map<TextAttribute, ?> attributes = font.getAttributes(); Map<TextAttribute, Object> newtributes = new HashMap<>(); newtributes.putAll(attributes); newtributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); header.setFont(font.deriveFont(newtributes)); } add(header); addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { parent.dispatchEvent(e); MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); parent.setEscaped(false); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { if (parent.isEscaped()) { MonthDay releasedDay = parent.getMonthDayAtCursor(); Displayable selected = MainPanel.getInstance().getSelectedEvent(); if (selected != null && releasedDay != null) { MutableDateTime newTime = new MutableDateTime(selected.getStart()); newTime.setYear(releasedDay.day.getYear()); newTime.setDayOfYear(releasedDay.day.getDayOfYear()); selected.setTime(newTime.toDateTime()); selected.update(); } } parent.dispatchEvent(e); } @Override public void mouseEntered(MouseEvent e) { parent.dispatchEvent(e); } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); parent.setEscaped(true); } }); header.addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); } @Override public void mouseClicked(MouseEvent e) { MainPanel.getInstance().miniMove(day); MainPanel.getInstance().viewDay(); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { parent.repaint(); parent.dispatchEvent(e); } @Override public void mouseMoved(MouseEvent e) { parent.dispatchEvent(e); } }); }
From source file:com.todoroo.andlib.utility.DateUtilities.java
License:Open Source License
/** * Add the specified amount of months to the given time.<br/> * The day of month will stay the same.<br/> * * @param time the base-time (in milliseconds) to which the amount of months is added * @param interval the amount of months to be added * @return the calculated time in milliseconds *//* ww w. j av a 2 s. co m*/ public static long addCalendarMonthsToUnixtime(long time, int interval) { DateTime dt = new DateTime(time); DateTime result = dt.plusMonths(interval); // preserving java.util.date behavior int diff = dt.getDayOfMonth() - result.getDayOfMonth(); if (diff > 0) { result = result.plusDays(diff); } return result.getMillis(); }
From source file:com.todoroo.astrid.repeats.RepeatControlSet.java
License:Open Source License
private void repeatUntilClick() { MyDatePickerDialog dialog = new MyDatePickerDialog(); DateTime initial = newDateTime(); dialog.initialize(new DatePickerDialog.OnDateSetListener() { @Override/*from ww w .j a va 2 s . c om*/ public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) { setRepeatUntilValue(new DateTime(year, month + 1, day, 0, 0, 0, 0).getMillis()); } }, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth(), false); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setRepeatUntilValue(repeatUntilValue); } }); dialog.show(activity.getSupportFragmentManager(), FRAG_TAG_REPEAT_UNTIL); }