List of usage examples for org.joda.time MutableDateTime setDayOfMonth
public void setDayOfMonth(final int dayOfMonth)
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);/*w w w . j a v a 2s .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); } 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.carmatech.cassandra.ShardingFrequency.java
License:Apache License
public static long calculateBucket(final long timestamp, final ShardingFrequency frequency) { final MutableDateTime dateTime = new MutableDateTime(timestamp); if (frequency.compareTo(SECONDLY) >= 0) dateTime.setMillisOfSecond(0);// w ww . ja v a 2 s.co m if (frequency.compareTo(MINUTELY) >= 0) dateTime.setSecondOfMinute(0); if (frequency.compareTo(HOURLY) >= 0) dateTime.setMinuteOfHour(0); if (frequency.compareTo(DAILY) >= 0) dateTime.setHourOfDay(0); if (frequency.compareTo(WEEKLY) >= 0) dateTime.setDayOfWeek(1); if (frequency.compareTo(MONTHLY) >= 0) dateTime.setDayOfMonth(1); return dateTime.getMillis(); }
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 w w w .ja v a2 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 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);// w w w. j a v a2 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 ww w .j a va 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 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);//w w w .j ava2 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 X and x//w ww . j ava2s. c o m * @param cal * @param yr * @param mo * @param da * @param firstDay: the first day of week * @return the year for this week, could be the same as yr or different * , depending on the first day of year */ private static int getYear(MutableDateTime cal, int yr, int mo, int da, int firstDay) { if (mo > 1 || da > 7) return yr; cal.setYear(yr); cal.setMonthOfYear(1); cal.setDayOfMonth(1); int firstD = 1; while (cal.getDayOfWeek() != firstDay) cal.setDayOfMonth(++firstD); // reset cal cal.setYear(yr); cal.setMonthOfYear(mo); cal.setDayOfMonth(da); if (da < firstD) return yr - 1; else return yr; }
From source file:com.foundationdb.server.types.texpressions.DateTimeField.java
License:Open Source License
/** * to be used in V, v, U and u/*from ww w.ja v a2 s. 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.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private DateTime getNextScheduleDay(DateTime midnightTomorrow) { switch (schedule.getScheduleType()) { case SignalSchedule.DAILY: return nextRepeatDaily(midnightTomorrow); case SignalSchedule.WEEKDAY: int tomorrowDOW = midnightTomorrow.getDayOfWeek(); if (tomorrowDOW > DateTimeConstants.FRIDAY) { return midnightTomorrow.plusDays(8 - tomorrowDOW); } else {//from w w w . jav a2 s .c om return midnightTomorrow; } case SignalSchedule.WEEKLY: int scheduleDays = schedule.getWeekDaysScheduled(); if (scheduleDays == 0) { return null; } for (int i = 0; i < 8; i++) { // go at least to the same day next week. int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek(); Integer nowDowIndex = SignalSchedule.DAYS_OF_WEEK[midnightTomorrowDOW == 7 ? 0 : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the week so Sunday is 7 instead of 0. if ((scheduleDays & nowDowIndex) == nowDowIndex) { return nextRepeatWeekly(midnightTomorrow); } midnightTomorrow = midnightTomorrow.plusDays(1); } throw new IllegalStateException("Cannot get to here. Weekly must repeat at least once a week"); case SignalSchedule.MONTHLY: if (schedule.getByDayOfMonth()) { int midnightDOM = midnightTomorrow.getDayOfMonth(); int scheduledDOM = schedule.getDayOfMonth(); if (midnightDOM == scheduledDOM) { return midnightTomorrow; } else if (midnightDOM > scheduledDOM) { MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime(); mutableDateTime.setDayOfMonth(scheduledDOM); return nextRepeatMonthly(mutableDateTime.toDateTime()); } else { return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM)); } } else { Integer nthOfMonth = schedule.getNthOfMonth(); Integer dow = getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow DateMidnight nthDowDate = getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight(); DateTime returnDate = null; if (nthDowDate.equals(midnightTomorrow)) { returnDate = midnightTomorrow; } else if (nthDowDate.isAfter(midnightTomorrow)) { returnDate = nthDowDate.toDateTime(); } else { returnDate = getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime(); } return nextRepeatMonthly(returnDate); } default: throw new IllegalStateException("Schedule has an unknown type: " + schedule.getScheduleType()); } }
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);/*from w w w . ja va 2 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(); }