Example usage for org.joda.time DateTime getMillisOfDay

List of usage examples for org.joda.time DateTime getMillisOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillisOfDay.

Prototype

public int getMillisOfDay() 

Source Link

Document

Get the millis of day field value.

Usage

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

public DateTime getNextTimeTodayForSchedule(DateTime now, DateTime nowMidnight, SignalSchedule schedule,
        Long experimentId) {//from   w w  w. j ava  2  s  . c  o m
    int nowAsOffsetFromMidnight = now.getMillisOfDay();
    List<SignalTimeHolder> previousTimes = Lists.newArrayList();
    for (int i = 0; i < schedule.getSignalTimes().size(); i++) {
        SignalTime signalTime = schedule.getSignalTimes().get(i);
        SignalTimeHolder signalTimeHolder = getTimeForSignalType(signalTime, previousTimes, nowMidnight,
                experimentId);

        if (signalTimeHolder.chosenTime != null
                && signalTimeHolder.chosenTime.getMillisOfDay() > nowAsOffsetFromMidnight) {
            return signalTimeHolder.chosenTime;
        }
        previousTimes.add(signalTimeHolder);
    }
    return null;
}

From source file:com.google.sampling.experiential.model.Experiment.java

License:Open Source License

@JsonIgnore
private DateTime getEndDateTime() {
    if (getSchedule() != null
            && getSchedule().getScheduleType().equals(com.pacoapp.paco.shared.model2.Schedule.WEEKDAY)) {
        List<SignalTime> signalTimes = schedule.getSignalTimes();
        List<Integer> times = Lists.newArrayList();
        for (SignalTime signalTime : signalTimes) {
            // TODO adjust for offset times and include them
            if (signalTime.getType() == com.pacoapp.paco.shared.model2.SignalTime.FIXED_TIME) {
                times.add(signalTime.getFixedTimeMillisFromMidnight());
            }//  w  w w .ja va2 s  .  c  om
        }
        // get the latest time
        Collections.sort(times);
        DateTime lastTimeForDay = new DateTime().plus(times.get(times.size() - 1));
        return new DateMidnight(endDate).toDateTime().withMillisOfDay(lastTimeForDay.getMillisOfDay());
    } else /*if (getScheduleType().equals(SCHEDULE_TYPE_ESM))*/ {
        return new DateMidnight(endDate).plusDays(1).toDateTime();
    }
}

From source file:com.marklogic.samplestack.dbclient.DateFacetBuilder.java

License:Apache License

public static ObjectNode dateFacet(DateTime min, DateTime max) {
    DateFacetBuilder fb = new DateFacetBuilder(new CustomObjectMapper());
    fb.name("date");
    /*//ww w .ja v  a2  s  .c om
    long interval = max.getMillis() - min.getMillis();
    if (interval / BucketInterval.BY_DAY.bucketDuration() < 40) {
       fb.period("DAY");
       DateTime bucketStart = min.minus(min.getMillisOfDay());
       while (bucketStart.isBefore(max)) {
    DateTime bucketEnd = bucketStart.plusDays(1);
    fb.bucket(bucketStart, bucketEnd);
    bucketStart = bucketStart.plusDays(1);
       }
    }
    else if (interval / BucketInterval.BY_WEEK.bucketDuration() < 40) {
       fb.period("WEEK");
       DateTime bucketStart = min.minusDays(min.getDayOfWeek()).minus(min.getMillisOfDay());
       while (bucketStart.isBefore(max)) {
    DateTime bucketEnd = bucketStart.plusWeeks(1);
    fb.bucket(bucketStart, bucketEnd);
    bucketStart = bucketStart.plusWeeks(1);
       }
    } else {
    */
    // for 8.0-1 we are only doing facets by month
    fb.period("MONTH");
    DateTime bucketStart = min.minusDays(min.getDayOfMonth() - 1).minus(min.getMillisOfDay());
    bucketStart = new DateTime(bucketStart);
    while (bucketStart.isBefore(max)) {
        DateTime bucketEnd = bucketStart.plusMonths(1);
        fb.bucket(bucketStart, bucketEnd);
        bucketStart = bucketStart.plusMonths(1);
    }
    // }
    return fb.facetNode;
}

From source file:com.nesscomputing.quartz.QuartzJob.java

License:Apache License

/**
 * Set the time-of-day when the first run of the job will take place.
 *//*  www .java 2s  . c om*/
@SuppressWarnings("unchecked")
public final SelfType startTime(final DateTime when, final TimeSpan jitter) {
    // Find the current week day in the same time zone as the "when" time passed in.
    final DateTime now = new DateTime().withZone(when.getZone());

    final int startWeekDay = when.getDayOfWeek();
    final int currentWeekDay = now.getDayOfWeek();

    // ( x + n ) % n is x for x > 0 and n - x for x < 0.
    final int daysTilStart = (startWeekDay - currentWeekDay + DAYS_PER_WEEK) % DAYS_PER_WEEK;
    Preconditions.checkState(daysTilStart >= 0 && daysTilStart < DAYS_PER_WEEK,
            "daysTilStart must be 0..%s, but is %s", DAYS_PER_WEEK, daysTilStart);

    // same trick as above, add a full week in millis and do the modulo.
    final long millisecondsTilStart = (when.getMillisOfDay() - now.getMillisOfDay()
            + daysTilStart * MILLIS_PER_DAY + MILLIS_PER_WEEK) % MILLIS_PER_WEEK;
    Preconditions.checkState(millisecondsTilStart >= 0 && millisecondsTilStart < MILLIS_PER_WEEK,
            "millisecondsTilStart must be 0..%s, but is %s", MILLIS_PER_WEEK, millisecondsTilStart);

    this.delay = Duration.millis(
            (long) (ThreadLocalRandom.current().nextDouble() * jitter.getMillis()) + millisecondsTilStart);
    return (SelfType) this;
}

From source file:com.pacoapp.paco.shared.scheduling.NonESMSignalGenerator.java

License:Open Source License

public DateTime getNextTimeTodayForSchedule(DateTime now, DateTime nowMidnight, Schedule schedule,
        Long experimentId) {//from  ww  w.j a v a2 s .  co m
    int nowAsOffsetFromMidnight = now.getMillisOfDay();
    List<SignalTimeHolder> previousTimes = new ArrayList();
    for (int i = 0; i < schedule.getSignalTimes().size(); i++) {
        SignalTime signalTime = schedule.getSignalTimes().get(i);
        SignalTimeHolder signalTimeHolder = getTimeForSignalType(signalTime, previousTimes, nowMidnight,
                experimentId);

        if (signalTimeHolder.chosenTime != null
                && signalTimeHolder.chosenTime.getMillisOfDay() > nowAsOffsetFromMidnight) {
            return signalTimeHolder.chosenTime;
        }
        previousTimes.add(signalTimeHolder);
    }
    return null;
}

From source file:com.pandits.opensource.JodaTimeUtil.java

License:Open Source License

public long getSecondsOfDayInMillis(long timeInMillis, TimeZone timeZone) {
    DateTime dateTime = createDateTime(timeInMillis, timeZone);
    return dateTime.getMillisOfDay();
}

From source file:com.serotonin.mango.util.DateUtils.java

License:Open Source License

public static DateTime truncateDateTime(DateTime time, int periodType) {
    if (periodType == TimePeriods.SECONDS)
        time = time.minus(time.getMillisOfSecond());
    else if (periodType == TimePeriods.MINUTES) {
        time = time.minus(time.getMillisOfSecond());
        time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute()));
    } else if (periodType == TimePeriods.HOURS) {
        time = time.minus(time.getMillisOfSecond());
        time = time.minus(Common.getPeriod(TimePeriods.SECONDS, time.getSecondOfMinute()));
        time = time.minus(Common.getPeriod(TimePeriods.MINUTES, time.getMinuteOfHour()));
    } else if (periodType == TimePeriods.DAYS) {
        time = time.minus(time.getMillisOfDay());
    } else if (periodType == TimePeriods.WEEKS) {
        time = time.minus(time.getMillisOfDay());
        time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfWeek() - 1));
    } else if (periodType == TimePeriods.MONTHS) {
        time = time.minus(time.getMillisOfDay());
        time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfMonth() - 1));
    } else if (periodType == TimePeriods.YEARS) {
        time = time.minus(time.getMillisOfDay());
        time = time.minus(Common.getPeriod(TimePeriods.DAYS, time.getDayOfYear() - 1));
    }/*from  ww  w  . j  a v a2 s.co m*/
    return time;
}

From source file:com.sos.jobnet.creator.FrequencyChecker.java

License:Apache License

public void processJobNet(JobNetPlanDBItem bootstrapOrder) {

    String uuid = bootstrapOrder.getUuid();
    logger.info(msg.getMsg(JOBNETCH_I_0001, uuid)); // processing jobnet with id %1$s.
    logger.debug(msg.getMsg(JOBNETCH_D_0002, bootstrapOrder.getNodeId())); // bootstrap order has node id %2$s.

    Date d = bootstrapOrder.getPlannedStartTime();
    if (d == null) {
        String msgText = msg.getMsg(JOBNETCH_E_0001); // bootstrap order has no single_start
        logger.error(msgText);/*from www .ja v  a 2 s.  c o m*/
        throw new JobNetException(msgText);
    }
    DateTime from = new DateTime(d);
    from = from.minusMillis(from.getMillisOfDay());
    DateTime to = from.plusDays(1);
    Interval baseInterval = new Interval(from, to);
    logger.debug(msg.getMsg(JOBNETCH_D_0001, fmtDateTime.print(from), fmtDateTime.print(to))); // searching for start times of job net nodes from %1$s to %2$s
    LocalDate forDay = new LocalDate(from);

    //      logger.debug(msg.getMsg(JOBNETCH_D_0003,fmtDate.print(baseInterval.getStart()))); // searching for starts at %2$s.
    List<JobNetPlanDBItem> jobnetOrders = getJobnet(uuid);
    if (jobnetOrders == null) {
        String msgText = msg.getMsg(JOBNETCH_E_0002, uuid);
        logger.error(msgText); // no jobnet found for UUID %1$s.
        throw new JobSchedulerException(msgText);
    }

    logger.debug(msg.getMsg(JOBNETCH_D_0004, jobnetOrders.size())); // the jobnet contains %1$s nodes.
    factory.setUseDefaultPeriod(true); // allows the use of runtime elements without or with incomplete periods

    planDbLayer.beginTransaction();
    for (JobNetPlanDBItem currentOrder : jobnetOrders) {
        JobNetNodeDBItem currentNode = getJobNetNode(currentOrder.getNodeId());
        if (!currentOrder.getBootstrap()) { // the properties for the bootstrap order has to be set in JobNetPlanCreator
            if (currentOrder.getIsRunnerSkipped()) {
                logger.info(msg.getMsg(JOBNETCH_I_0002, currentNode.getNode(), currentOrder.getNodeId())); // order %1$s (node id %2$s) is already skipped.
            } else {
                JSObjOrder jsOrder = getJSObjOrder(currentOrder.getOrderXml());
                JSObjRunTime runTime = jsOrder.getJSObjRunTime();
                if (runTime.hasSubsequentRunTimes()) {
                    LocalDate startDay = getNextStartDayInIntervalOrNull(runTime, baseInterval);
                    if (startDay == null) {
                        currentOrder.setIsRunnerSkipped(true);
                        // order %1$s (node id %2$s) has no start time for %3$s and will be skipped.
                        logger.info(msg.getMsg(JOBNETCH_I_0003, currentNode.getNode(), currentOrder.getNodeId(),
                                fmtDate.print(forDay)));
                    } else {
                        // order %1$s (node id %2$s) has a start time for %3$s and will NOT skipped.
                        logger.debug(msg.getMsg(JOBNETCH_I_0005, currentNode.getNode(),
                                currentOrder.getNodeId(), fmtDate.print(forDay)));
                        if (currentOrder.getIsRunnerOnDemand()) {
                            // order %1$s (node id %2$s) has to be started on demand.
                            logger.info(msg.getMsg(JOBNETCH_I_0006, currentNode.getNode(),
                                    currentOrder.getNodeId()));
                            currentOrder.setIsRunnerOnDemand(true);
                        }
                    }
                } else {
                    if (currentOrder.getIsRunnerOnDemand()) {
                        // order %1$s (node id %2$s) has no start time and will be NOT skipped.
                        currentOrder.setIsRunnerOnDemand(true);
                        logger.info(
                                msg.getMsg(JOBNETCH_I_0004, currentNode.getNode(), currentOrder.getNodeId()));
                    } else {
                        logger.debug(
                                "nothing to do - order has neither a start_time nor the parameter on_demand.");
                    }
                }
                logger.debug(currentOrder.getOrderXml().replace("\n", ""));
                planDbLayer.update(currentOrder);

            }
        }
        logRecord(currentNode, currentOrder);
    }
    planDbLayer.commit();
}

From source file:com.sos.scheduler.model.objects.IntervalConstants.java

License:Apache License

public Interval getInterval() {
    DateTime from = new DateTime();
    DateTime to = null;/*w  w w . j a  v a 2  s . c om*/
    switch (this) {
    case CURRENT_DAY:
        from = from.minusMillis(from.getMillisOfDay());
        to = from.plusDays(1);
        break;
    case CURRENT_WEEK:
        from = from.minusMillis(from.getMillisOfDay()).minusDays(from.getDayOfWeek());
        to = from.plusWeeks(1);
        break;
    case REST_OF_DAY:
        to = from.minusMillis(from.getMillisOfDay()).plusDays(1);
        break;
    case NEXT_24H:
        to = from.plusDays(1);
        break;
    case NEXT_WEEK:
        to = from.plusWeeks(1);
        break;
    }
    return new Interval(from, to);
}

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

public static DateTime getDayInMonth(DateTime date, int day) {
    DateTime baseDate = (day > 1) ? date.minusMonths(1) : date;
    DateTime result = getEndOfMonth(baseDate).plusDays(day);
    return result.minusMillis(result.getMillisOfDay());
}