List of usage examples for org.joda.time MutableDateTime toDateTime
DateTime toDateTime();
From source file:au.org.intersect.dms.instrument.harvester.CellRMtbParser.java
License:Open Source License
private String convertPropertyValue(String name, Object value, Map<String, Object> row) { if (types.containsKey(name)) { if ("date".equals(types.get(name))) { MutableDateTime date = new MutableDateTime(value); Object timeValue = row.get("Document Creation Time"); LOGGER.trace("Converting date. Day: {}, time: {}", value, timeValue); DateTime time = new DateTime(timeValue); date.setTime(time);/*from w w w .j a v a 2s .c o m*/ LOGGER.trace("Date converted to: {}", date); return convertDate2UTC(date.toDateTime()); } } return value.toString(); }
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 w w w .j a 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); } 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:ch.windmobile.server.mongo.MongoDataSource.java
License:Open Source License
static protected DateTime getExpirationDate(DateTime now, DateTime lastUpdate) { MutableDateTime expirationDate = new MutableDateTime(lastUpdate.getZone()); if (isSummerFrequency(now)) { expirationDate.setMillis(lastUpdate.getMillis() + 20 * 60 * 1000); if (expirationDate.getHourOfDay() >= 20) { expirationDate.addDays(1);/*from w w w . j a v a 2 s. c o m*/ expirationDate.setHourOfDay(8); expirationDate.setMinuteOfHour(0); expirationDate.setSecondOfMinute(0); } } else { expirationDate.setMillis(lastUpdate.getMillis() + 60 * 60 * 1000); if (expirationDate.getHourOfDay() >= 17) { expirationDate.addDays(1); expirationDate.setHourOfDay(9); expirationDate.setMinuteOfHour(0); expirationDate.setSecondOfMinute(0); } } return expirationDate.toDateTime(); }
From source file:com.almende.eve.agent.MeetingAgent.java
License:Apache License
/** * Merge the busy intervals of all attendees, and the preferred intervals *//*from w w w. j a va2 s .c o m*/ private void mergeTimeConstraints() { final ArrayList<Interval> infeasibleIntervals = new ArrayList<Interval>(); final ArrayList<Weight> preferredIntervals = new ArrayList<Weight>(); final Activity activity = getActivity(); if (activity != null) { // read and merge the stored busy intervals of all attendees for (final Attendee attendee : activity.withConstraints().withAttendees()) { final String agent = attendee.getAgent(); if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) { if (new Boolean(true).equals(attendee.getOptional())) { // This attendee is optional. // Add its busy intervals to the soft constraints final List<Interval> attendeeBusy = getAgentBusy(agent); if (attendeeBusy != null) { for (final Interval i : attendeeBusy) { final Weight wi = new Weight(i.getStart(), i.getEnd(), WEIGHT_BUSY_OPTIONAL_ATTENDEE); preferredIntervals.add(wi); } } } else { // this attendee is required. // Add its busy intervals to the hard constraints final List<Interval> attendeeBusy = getAgentBusy(agent); if (attendeeBusy != null) { infeasibleIntervals.addAll(attendeeBusy); } } } // else This attendee declined. Ignore this attendees busy // interval } // read the time preferences and add them to the soft constraints final List<Preference> preferences = activity.withConstraints().withTime().withPreferences(); for (final Preference p : preferences) { if (p != null) { final Weight wi = new Weight(new DateTime(p.getStart()), new DateTime(p.getEnd()), p.getWeight()); preferredIntervals.add(wi); } } } // add office hours profile to the soft constraints // TODO: don't include (hardcoded) office hours here, should be handled // by a PersonalAgent final DateTime timeMin = DateTime.now(); final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS); final List<Interval> officeHours = IntervalsUtil.getOfficeHours(timeMin, timeMax); for (final Interval i : officeHours) { final Weight wi = new Weight(i, WEIGHT_OFFICE_HOURS); preferredIntervals.add(wi); } // add delay penalties to the soft constraints final DateTime now = DateTime.now(); final MutableDateTime d = new MutableDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0); for (int i = 0; i <= LOOK_AHEAD_DAYS; i++) { final DateTime start = d.toDateTime(); final DateTime end = start.plusDays(1); final Weight wi = new Weight(start, end, WEIGHT_DELAY_PER_DAY * i); preferredIntervals.add(wi); d.addDays(1); } // order and store the aggregated lists with intervals IntervalsUtil.order(infeasibleIntervals); getState().put("infeasible", infeasibleIntervals); WeightsUtil.order(preferredIntervals); getState().put("preferred", preferredIntervals); }
From source file:com.enonic.cms.core.search.ElasticSearchFormatter.java
License:Open Source License
public static ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) { if (DateTimeZone.UTC.equals(dateTime.getZone())) { return dateTime; }//from ww w. j a v a2s .com final MutableDateTime dateInUTC = dateTime.toMutableDateTime(); dateInUTC.setZone(DateTimeZone.UTC); return dateInUTC.toDateTime(); }
From source file:com.enonic.cms.core.search.query.factory.FilterQueryBuilderFactory.java
License:Open Source License
private ReadableDateTime toUTCTimeZone(final ReadableDateTime dateTime) { if (DateTimeZone.UTC.equals(dateTime.getZone())) { return dateTime; }/*from ww w . jav a2 s . c o m*/ final MutableDateTime dateInUTC = dateTime.toMutableDateTime(); dateInUTC.setZone(DateTimeZone.UTC); return dateInUTC.toDateTime(); }
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 . j a v a2 s .co m 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 ww . jav a 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:com.metamx.druid.http.FileRequestLogger.java
License:Open Source License
@LifecycleStart public void start() { try {// ww w . j av a2 s .c o m baseDir.mkdirs(); MutableDateTime mutableDateTime = new DateTime().toMutableDateTime(); mutableDateTime.setMillisOfDay(0); currentDay = mutableDateTime.toDateTime(); fileWriter = new FileWriter(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true); long nextDay = currentDay.plusDays(1).getMillis(); Duration delay = new Duration(nextDay - new DateTime().getMillis()); ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() { @Override public ScheduledExecutors.Signal call() { currentDay = currentDay.plusDays(1); try { synchronized (lock) { Closeables.closeQuietly(fileWriter); fileWriter = new FileWriter(new File(baseDir, currentDay.toString()), true); } } catch (Exception e) { Throwables.propagate(e); } return ScheduledExecutors.Signal.REPEAT; } }); } catch (IOException e) { Throwables.propagate(e); } }
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 w w .j a v a2s . com 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()); } }