List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:com.squarespace.template.plugins.PluginDateUtils.java
License:Apache License
private static void formatAggregate(DateTimeAggregate type, Locale locale, DateTime date, StringBuilder buf) { switch (type) { case FULL:/*from w ww. ja va 2s.c o m*/ buf.append(date.dayOfWeek().getAsShortText(locale)); buf.append(' '); leftPad(date.dayOfMonth().get(), '0', 2, buf); buf.append(' '); buf.append(date.monthOfYear().getAsShortText(locale)); buf.append(' '); buf.append(date.year().get()); buf.append(' '); leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf); buf.append(':'); leftPad(date.minuteOfHour().get(), '0', 2, buf); buf.append(':'); leftPad(date.secondOfMinute().get(), '0', 2, buf); buf.append(' '); buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM"); buf.append(' '); buf.append(date.getZone().getNameKey(date.getMillis())); break; case H240_M0: leftPad(date.get(DateTimeFieldType.clockhourOfDay()), '0', 2, buf); buf.append(':'); leftPad(date.minuteOfHour().get(), '0', 2, buf); break; case HHMMSSP: leftPad(date.get(DateTimeFieldType.hourOfHalfday()), '0', 2, buf); buf.append(':'); leftPad(date.getMinuteOfHour(), '0', 2, buf); buf.append(':'); leftPad(date.getSecondOfMinute(), '0', 2, buf); buf.append(' '); buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM"); break; case MMDDYY: leftPad(date.getMonthOfYear(), '0', 2, buf); buf.append('/'); leftPad(date.dayOfMonth().get(), '0', 2, buf); buf.append('/'); leftPad(date.yearOfCentury().get(), '0', 2, buf); break; case MMDDYYYY: leftPad(date.getMonthOfYear(), '0', 2, buf); buf.append('/'); leftPad(date.dayOfMonth().get(), '0', 2, buf); buf.append('/'); buf.append(date.getYear()); break; case YYYYMMDD: buf.append(date.year().get()); buf.append('-'); leftPad(date.monthOfYear().get(), '0', 2, buf); buf.append('-'); leftPad(date.dayOfMonth().get(), '0', 2, buf); break; default: break; } }
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisCompute.java
License:Open Source License
private IntervalleObject alignPastInterval(IntervalleObject presentInterval, IntervalleObject pastInterval, Axis joinAxis) throws ScopeException { if (joinAxis != null && presentInterval != null && pastInterval != null) { Object lowerPresent = presentInterval.getLowerBound(); Object lowerPast = pastInterval.getLowerBound(); Object upperPresent = presentInterval.getUpperBound(); Object upperPast = pastInterval.getUpperBound(); ///*ww w .j a v a2 s. co m*/ IDomain image = joinAxis.getDefinition().getImageDomain(); if (lowerPresent instanceof Date && lowerPast instanceof Date) { DateTime lowerPastDT = new DateTime((Date) lowerPast); DateTime lowerPresentDT = new DateTime((Date) lowerPresent); DateTime upperPresentDT = new DateTime((Date) upperPresent); DateTime upperPastDT = new DateTime((Date) upperPast); // realign if (image.isInstanceOf(IDomain.YEARLY)) { // check if present is an exact number of years if (lowerPresentDT.getDayOfYear() == 1 && upperPresentDT.getDayOfYear() == upperPresentDT.dayOfYear().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.years()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.years()); // realign if (presentPeriod.getYears() > pastPeriod.getYears()) { // some days are missing to align the periods if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(upperPastDT.getYear(), 1, 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over year Date newUpperPast = new DateTime(upperPastDT.getYear(), 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } else { // either already aligned, or some days should // be removed if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over Year Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } else if (image.isInstanceOf(IDomain.QUATERLY) || image.isInstanceOf(IDomain.MONTHLY)) { // check if present is an exact number of month if (lowerPresentDT.getDayOfMonth() == 1 && upperPresentDT.getDayOfMonth() == upperPresentDT.dayOfMonth().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), new LocalDate(upperPresent), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), new LocalDate(upperPast), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { // realign presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.months()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.months()); if (presentPeriod.getMonths() > pastPeriod.getMonths()) { // some days are missing if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { // month over month Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfMonth() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } else { // either already aligned, of some days should // be removed if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { /// month over month if (upperPastDT.getMonthOfYear() == 1) { Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } else { upperPastDT = upperPastDT.minusMonths(1); Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } if (lowerPastDT.getDayOfMonth() != 1) { // previous period if (lowerPastDT.getMonthOfYear() == 12) { Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } else { lowerPastDT = lowerPastDT.plusMonths(1); Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } } } } return pastInterval; }
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(); ///*from w ww. j a v a 2 s. co 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.//from w w w . j a v a 2 s . c o 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.tech.auju.implementation.PembelianImpl.java
/** * Get today date./* ww w . j a v a 2 s . c o m*/ * @return Today date. */ private Date getTime() { DateTime dt = new DateTime(); int d = dt.getDayOfWeek(); int m = dt.getMonthOfYear(); int y = dt.getYear(); 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 ava2s.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(); }//from w ww . java2 s . c o m }
From source file:com.tkmtwo.sarapi.support.ValueUtil.java
License:Apache License
public static DateInfo toDateInfo(DateTime dt) { if (dt == null) { return null; }/*w w w .j a va 2 s . c o m*/ return new DateInfo(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth()); }
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 ww .ja va 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.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.ja v a 2 s .c o m*/ 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); }