List of usage examples for org.joda.time MutableDateTime getMinuteOfHour
public int getMinuteOfHour()
From source file:br.com.centralit.evm.citsmartevm.util.CronExpression.java
License:Apache License
public DateTime nextTimeAfter(DateTime afterTime) { MutableDateTime nextTime = new MutableDateTime(afterTime); nextTime.setMillisOfSecond(0);/*from ww w. ja va2 s. c om*/ nextTime.secondOfDay().add(1); while (true) { // day of week while (true) { // month while (true) { // day of month while (true) { // hour while (true) { // minute while (true) { // second if (secondField.matches(nextTime.getSecondOfMinute())) { break; } nextTime.secondOfDay().add(1); } if (minuteField.matches(nextTime.getMinuteOfHour())) { break; } nextTime.minuteOfDay().add(1); nextTime.secondOfMinute().set(0); } if (hourField.matches(nextTime.getHourOfDay())) { break; } nextTime.hourOfDay().add(1); nextTime.minuteOfHour().set(0); nextTime.secondOfMinute().set(0); } if (dayOfMonthField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); } if (monthField.matches(nextTime.getMonthOfYear())) { break; } nextTime.addMonths(1); nextTime.setDayOfMonth(1); nextTime.setTime(0, 0, 0, 0); } if (dayOfWeekField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); } return nextTime.toDateTime(); }
From source file:com.huffingtonpost.chronos.util.CronExpression.java
License:Apache License
@CoverageIgnore public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) { MutableDateTime nextTime = new MutableDateTime(afterTime); nextTime.setMillisOfSecond(0);//ww w .j a va2 s .c om nextTime.secondOfDay().add(1); while (true) { // day of week while (true) { // month while (true) { // day of month while (true) { // hour while (true) { // minute while (true) { // second if (secondField.matches(nextTime.getSecondOfMinute())) { break; } nextTime.secondOfDay().add(1); } if (minuteField.matches(nextTime.getMinuteOfHour())) { break; } nextTime.minuteOfDay().add(1); nextTime.secondOfMinute().set(0); } if (hourField.matches(nextTime.getHourOfDay())) { break; } nextTime.hourOfDay().add(1); nextTime.minuteOfHour().set(0); nextTime.secondOfMinute().set(0); } if (dayOfMonthField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (monthField.matches(nextTime.getMonthOfYear())) { break; } nextTime.addMonths(1); nextTime.setDayOfMonth(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (dayOfWeekField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } return nextTime.toDateTime(); }
From source file:com.tmathmeyer.sentinel.ui.tabs.AddCommitmentDisplay.java
License:Open Source License
/** * Sets the default date and time text fields to the current date and time * //from w ww .j a v a2s.c o m * Should be only called if creating a new commitment, not when editing * since edit event already has a date and time to fill the text fields with */ public void setCurrentDateAndTime() { this.startTimeDatePicker.setDate(selectedTime); MutableDateTime mdt = DateTime.now().toMutableDateTime(); int quarterHours = mdt.getMinuteOfHour() / 15; int minutes = quarterHours < 4 ? (quarterHours + 1) * 15 : (quarterHours) * 15; if (minutes == 60) { mdt.addHours(1); mdt.setMinuteOfHour(0); } else mdt.setMinuteOfHour(minutes); this.startTimeDatePicker.setTime(mdt.toDateTime()); }
From source file:com.tmathmeyer.sentinel.ui.tabs.AddEventDisplay.java
License:Open Source License
/** * Sets the default date and time text fields to the current date and time * //from ww w .j av a 2 s . c o m * Should be only called if creating a new event, not when editing since * edit event already has a date and time to fill the text fields with */ public void setCurrentDateAndTime() { this.startTimeDatePicker.setDate(selectedTime); this.endTimeDatePicker.setDate(selectedTime); MutableDateTime mdt = DateTime.now().toMutableDateTime(); int quarterHours = mdt.getMinuteOfHour() / 15; int minutes = quarterHours < 4 ? (quarterHours + 1) * 15 : (quarterHours) * 15; if (minutes == 60) { mdt.addHours(1); mdt.setMinuteOfHour(0); } else mdt.setMinuteOfHour(minutes); this.startTimeDatePicker.setTime(mdt.toDateTime()); mdt.addHours(1); this.endTimeDatePicker.setTime(mdt.toDateTime()); }
From source file:fc.cron.CronExpression.java
License:Apache License
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) { MutableDateTime nextTime = new MutableDateTime(afterTime); nextTime.setMillisOfSecond(0);/*from w w w .ja va 2 s .c o m*/ nextTime.secondOfDay().add(1); while (true) { // day of week while (true) { // month while (true) { // day of month while (true) { // hour while (true) { // minute while (true) { // second if (secondField.matches(nextTime.getSecondOfMinute())) { break; } nextTime.secondOfDay().add(1); } if (minuteField.matches(nextTime.getMinuteOfHour())) { break; } nextTime.minuteOfDay().add(1); nextTime.secondOfMinute().set(0); } if (hourField.matches(nextTime.getHourOfDay())) { break; } nextTime.hourOfDay().add(1); nextTime.minuteOfHour().set(0); nextTime.secondOfMinute().set(0); } if (dayOfMonthField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (monthField.matches(nextTime.getMonthOfYear())) { break; } nextTime.addMonths(1); nextTime.setDayOfMonth(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (dayOfWeekField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } return nextTime.toDateTime(); }
From source file:org.apache.wicket.extensions.yui.calendar.DateTimeField.java
License:Apache License
/** * @see org.apache.wicket.Component#onBeforeRender() */// ww w .j av a 2s.co m @Override protected void onBeforeRender() { dateField.setRequired(isRequired()); hoursField.setRequired(isRequired()); minutesField.setRequired(isRequired()); boolean use12HourFormat = use12HourFormat(); amOrPmChoice.setVisible(use12HourFormat); Date modelObject = (Date) getDefaultModelObject(); if (modelObject == null) { date = null; hours = null; minutes = null; } else { // convert date to the client's time zone if we have that info TimeZone zone = getClientTimeZone(); if (zone != null) { modelObject = changeTimeZone(modelObject, zone); } MutableDateTime mDate = new MutableDateTime(modelObject); date = mDate.toDate(); if (use12HourFormat) { int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday()); hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay; } else { hours = mDate.get(DateTimeFieldType.hourOfDay()); } amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM; minutes = mDate.getMinuteOfHour(); } super.onBeforeRender(); }
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 ww w . j a v a 2s . c om 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; }
From source file:org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField.java
License:Apache License
/** * @see org.apache.wicket.Component#onBeforeRender() *///w w w .jav a 2 s .c o m @Override protected void onBeforeRender() { dateField.setRequired(isRequired()); hoursField.setRequired(isRequired()); minutesField.setRequired(isRequired()); boolean use12HourFormat = use12HourFormat(); amOrPmChoice.setVisible(use12HourFormat); Date modelObject = (Date) getDefaultModelObject(); if (modelObject == null) { date = null; hours = null; minutes = null; } else { MutableDateTime mDate = new MutableDateTime(modelObject); // convert date to the client's time zone if we have that info TimeZone zone = getClientTimeZone(); if (zone != null) { mDate.setZone(DateTimeZone.forTimeZone(zone)); } date = mDate.toDateTime().toLocalDate().toDate(); if (use12HourFormat) { int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday()); hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay; } else { hours = mDate.get(DateTimeFieldType.hourOfDay()); } amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM; minutes = mDate.getMinuteOfHour(); } super.onBeforeRender(); }
From source file:org.wso2.analytics.esb.util.TimeRangeUtils.java
License:Open Source License
public static List<TimeRange> getDateTimeRanges(long from, long to) { List<TimeRange> ranges = new ArrayList<>(10); MutableDateTime fromDate = new MutableDateTime(from); fromDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime toDate = new MutableDateTime(to); toDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime tempFromTime = fromDate.copy(); MutableDateTime tempToTime = toDate.copy(); if (log.isDebugEnabled()) { log.debug("Time range: " + formatter.format(fromDate.toDate()) + " -> " + formatter.format(toDate.toDate())); }/*from www .ja v a 2 s.com*/ if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) { ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), toDate.getMillis() })); } else { if (tempFromTime.getSecondOfMinute() != 0 && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) { tempFromTime = tempFromTime.minuteOfHour().roundCeiling(); ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getMinuteOfHour() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) { tempFromTime = tempFromTime.minuteOfHour().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE); } else { tempFromTime = tempFromTime.hourOfDay().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getHourOfDay() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) { tempFromTime = tempFromTime.hourOfDay().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR); } else { tempFromTime = tempFromTime.dayOfMonth().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getDayOfMonth() != 1 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { fromDate = tempFromTime.copy(); if ((((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) { tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis()) / ((long) DateTimeConstants.MILLIS_PER_DAY))); } else { tempFromTime = tempFromTime.monthOfYear().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempToTime.getSecondOfMinute() != 0 && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) { toDate = tempToTime.copy(); long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND; if (remainingSeconds < 60) { tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds); } else { tempToTime = tempToTime.secondOfMinute().roundFloor(); } ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { toDate = tempToTime.copy(); long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE; if (remainingMinutes < 60) { tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes); } else { tempToTime = tempToTime.hourOfDay().roundFloor(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getHourOfDay() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { toDate = tempToTime.copy(); long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR; if (remainingHours < 24) { tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours); } else { tempToTime = tempToTime.dayOfMonth().roundFloor(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getDayOfMonth() != 1 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { toDate = tempToTime.copy(); tempToTime = tempToTime.monthOfYear().roundFloor(); ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.isAfter(tempFromTime)) { ranges.add(new TimeRange(RangeUnit.MONTH.name(), new long[] { tempFromTime.getMillis(), tempToTime.getMillis() })); } } if (log.isDebugEnabled()) { for (TimeRange timeRange : ranges) { log.debug("Unit: " + timeRange.getUnit() + " Range: " + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0] + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "(" + timeRange.getRange()[1] + ")"); } } return ranges; }
From source file:org.wso2.analytics.shared.util.time.TimeRangeUtils.java
License:Open Source License
public static List<TimeRange> getDateTimeRanges(long from, long to) { List<TimeRange> ranges = new ArrayList<>(10); MutableDateTime fromDate = new MutableDateTime(from); fromDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime toDate = new MutableDateTime(to); toDate.set(DateTimeFieldType.millisOfSecond(), 0); MutableDateTime tempFromTime = fromDate.copy(); MutableDateTime tempToTime = toDate.copy(); if (log.isDebugEnabled()) { log.debug("Time range: " + formatter.format(fromDate.toDate()) + "->" + formatter.format(toDate.toDate())); }//from w w w.j ava 2 s.c om if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) { ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), toDate.getMillis() })); } else { if (tempFromTime.getSecondOfMinute() != 0 && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) { tempFromTime = tempFromTime.minuteOfHour().roundCeiling(); ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getMinuteOfHour() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) { tempFromTime = tempFromTime.minuteOfHour().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE); } else { tempFromTime = tempFromTime.hourOfDay().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getHourOfDay() != 0 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { fromDate = tempFromTime.copy(); if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) { tempFromTime = tempFromTime.hourOfDay().add( (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR); } else { tempFromTime = tempFromTime.dayOfMonth().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempFromTime.getDayOfMonth() != 1 && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { fromDate = tempFromTime.copy(); if ((((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) { tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis()) / ((long) DateTimeConstants.MILLIS_PER_DAY))); } else { tempFromTime = tempFromTime.monthOfYear().roundCeiling(); } ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { fromDate.getMillis(), tempFromTime.getMillis() })); } if (tempToTime.getSecondOfMinute() != 0 && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) { toDate = tempToTime.copy(); long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND; if (remainingSeconds < 60) { tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds); } else { tempToTime = tempToTime.secondOfMinute().roundFloor(); } ranges.add(new TimeRange(RangeUnit.SECOND.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) { toDate = tempToTime.copy(); long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE; if (remainingMinutes < 60) { tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes); } else { tempToTime = tempToTime.hourOfDay().roundFloor(); } ranges.add(new TimeRange(RangeUnit.MINUTE.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getHourOfDay() != 0 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) { toDate = tempToTime.copy(); long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis()) % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR; if (remainingHours < 24) { tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours); } else { tempToTime = tempToTime.dayOfMonth().roundFloor(); } ranges.add(new TimeRange(RangeUnit.HOUR.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.getDayOfMonth() != 1 && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) { toDate = tempToTime.copy(); tempToTime = tempToTime.monthOfYear().roundFloor(); ranges.add(new TimeRange(RangeUnit.DAY.name(), new long[] { tempToTime.getMillis(), toDate.getMillis() })); } if (tempToTime.isAfter(tempFromTime)) { ranges.add(new TimeRange(RangeUnit.MONTH.name(), new long[] { tempFromTime.getMillis(), tempToTime.getMillis() })); } } if (log.isDebugEnabled()) { for (TimeRange timeRange : ranges) { log.debug("Unit: " + timeRange.getUnit() + " Range: " + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0] + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "(" + timeRange.getRange()[1] + ")"); } } return ranges; }