List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:com.pacoapp.paco.shared.scheduling.NonESMSignalGenerator.java
License:Open Source License
private DateTime getNextScheduleDay(DateTime midnightTomorrow) { switch (schedule.getScheduleType()) { case Schedule.DAILY: return nextRepeatDaily(midnightTomorrow); case Schedule.WEEKDAY: int tomorrowDOW = midnightTomorrow.getDayOfWeek(); if (tomorrowDOW > DateTimeConstants.FRIDAY) { return midnightTomorrow.plusDays(8 - tomorrowDOW); } else {/*from w ww . j a va2 s . co m*/ return midnightTomorrow; } case Schedule.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 = Schedule.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 Schedule.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.pureblue.quant.util.frequency.Daily.java
@Override public DateTime periodBegin(DateTime t) { DateTime currentDayStart = new DateTime(t.getYear(), t.getMonthOfYear(), t.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), t.getZone());//from w w w. j a v a2 s.co m if (currentDayStart.isAfter(t)) { return currentDayStart.minusDays(1); } else { return currentDayStart; } }
From source file:com.pureblue.quant.util.frequency.Hourly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), 0, 0, 0, time.getZone());//from www. j av a 2 s . co m }
From source file:com.pureblue.quant.util.frequency.Minute.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), 0, 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Second.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Weekly.java
@Override public DateTime periodBegin(DateTime time) { int timeDifference = time.getDayOfWeek() - day.toJodaTimeValue(); if (timeDifference < 0) { timeDifference += 7;/*from w w w . java 2 s .c o m*/ } DateTime startDay = time.minusDays(timeDifference); DateTime weekStart = new DateTime(startDay.getYear(), startDay.getMonthOfYear(), startDay.getDayOfMonth(), dayStartTime.getHourOfDay(), dayStartTime.getMinuteOfHour(), dayStartTime.getSecondOfMinute(), dayStartTime.getMillisOfSecond(), startDay.getZone()); if (weekStart.isAfter(time)) { return weekStart.minusWeeks(1); } else { return weekStart; } }
From source file:com.qcadoo.model.internal.types.DateType.java
License:Open Source License
@Override public ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value) { if (value instanceof Date) { return ValueAndError.withoutError(value); }//from w w w . j a v a2 s. c o m try { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateUtils.L_DATE_FORMAT); DateTime dt = fmt.parseDateTime(String.valueOf(value)); int year = dt.getYear(); if (year < 1500 || year > 2500) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat.range"); } Date date = dt.toDate(); if (year < 2000) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, dt.getYear()); c.set(Calendar.MONTH, dt.getMonthOfYear() - 1); c.set(Calendar.DAY_OF_MONTH, dt.getDayOfMonth()); c.set(Calendar.HOUR_OF_DAY, dt.hourOfDay().get()); c.set(Calendar.MINUTE, dt.getMinuteOfHour()); c.set(Calendar.SECOND, dt.getSecondOfMinute()); c.set(Calendar.MILLISECOND, dt.getMillisOfSecond()); date = c.getTime(); } return ValueAndError.withoutError(date); } catch (IllegalArgumentException e) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat"); } }
From source file:com.robwilliamson.healthyesther.reminder.TimingModel.java
License:Open Source License
private RangeSet allowedTimes() { DateTime yesterday = mEnvironment.getNow().minus(Duration.standardDays(1)); return mAllowedNotificationTimes.startingFrom(yesterday.getYear(), yesterday.getMonthOfYear(), yesterday.getDayOfMonth()); }
From source file:com.robwilliamson.healthyesther.util.time.RangeSet.java
License:Open Source License
@Override public RangeSet startingFrom(int year, int monthOfYear, int dayOfMonth) { Duration shift = Duration .millis(from.withDate(year, monthOfYear, dayOfMonth).getMillis() - from.getMillis()); Set<TimeRegion> regions = new HashSet<>(mTimeRegions.size()); for (TimeRegion region : mTimeRegions) { DateTime newFrom = region.from.plus(shift); regions.add(region.startingFrom(newFrom.getYear(), newFrom.getMonthOfYear(), newFrom.getDayOfMonth())); }/*from w ww.j a v a2 s . c om*/ return new RangeSet(regions.toArray(new TimeRegion[] {})); }
From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java
License:Open Source License
private static DateTime dateTimeCeiling(DateTime dt, Period p) { if (p.getYears() != 0) { return dt.yearOfEra().roundCeilingCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundCeilingCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundCeilingCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundCeilingCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundCeilingCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundCeilingCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundCeilingCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }// ww w . j av a 2 s. c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }