Example usage for org.joda.time DateTime getHourOfDay

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

Introduction

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

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:org.openvpms.web.workspace.workflow.appointment.TimeRange.java

License:Open Source License

/**
 * Returns the time range that the specified time falls into.
 *
 * @param time the time/*from   ww w.j  a  v  a2 s. c  om*/
 * @return the corresponding time range
 */
public static TimeRange getRange(Date time) {
    DateTime dateTime = new DateTime(time);
    int hour = dateTime.getHourOfDay();
    if (hour < 8) {
        return AM;
    } else if (hour >= 8 && hour < 12) {
        return MORNING;
    } else if (hour >= 12 && hour < 17) {
        return AFTERNOON;
    } else if (hour >= 17) {
        return EVENING;
    }
    return ALL;
}

From source file:org.openvpms.web.workspace.workflow.appointment.TimeRange.java

License:Open Source License

/**
 * Returns one of {@link #AM}, or {@link #PM} based on the supplied time.
 *
 * @param time the time//from  www.  ja v a 2 s.  co  m
 * @return the corresponding time range
 */
public static TimeRange getAMorPM(DateTime time) {
    return time.getHourOfDay() < 12 ? AM : PM;
}

From source file:org.openvpms.web.workspace.workflow.appointment.TimeRange.java

License:Open Source License

/**
 * Returns one of {@link #MORNING}, {@link #AFTERNOON} or {@link #EVENING} based on the supplied time.
 *
 * @param time the time//from   w  ww .  j a v  a 2  s  . co  m
 * @return the corresponding time range
 */
public static TimeRange getMorningOrAfternoonOrEvening(DateTime time) {
    int hour = time.getHourOfDay();
    if (hour < 12) {
        return MORNING;
    } else if (hour < 15) {
        return AFTERNOON;
    }
    return EVENING;
}

From source file:org.pidome.server.services.clients.remoteclient.RemoteClient.java

License:Apache License

/**
 * Returns the date since this client connected (From successful login).
 * @return /*from w  w  w.  j  a  v a  2 s  .c o m*/
 */
public final String getConnectedSinceDateTime() {
    DateTime dt = new DateTime(connectedSince);
    return TimeUtils.composeDDMMYYYYDate(dt.getDayOfMonth(), dt.getMonthOfYear(), dt.getYear()) + " "
            + TimeUtils.compose24Hours(dt.getHourOfDay(), dt.getMinuteOfHour());
}

From source file:org.powertac.common.Rate.java

License:Apache License

/**
 * True just in case this Rate applies at the given DateTime, ignoring the
 * tier.//from   ww  w  .j a  v a  2 s. c om
 */
public boolean applies(AbstractInstant when) {
    boolean appliesWeekly = false;
    boolean appliesDaily = false;
    DateTime time = new DateTime(when, DateTimeZone.UTC);

    // check weekly applicability
    int day = time.getDayOfWeek();
    if (weeklyBegin == NO_TIME || weeklyEnd == NO_TIME) {
        appliesWeekly = true;
    } else if (weeklyEnd >= weeklyBegin) {
        appliesWeekly = (day >= weeklyBegin && day <= weeklyEnd);
    } else {
        appliesWeekly = (day >= weeklyBegin || day <= weeklyEnd);
    }

    // check daily applicability
    int hour = time.getHourOfDay();
    if (dailyBegin == NO_TIME || dailyEnd == NO_TIME) {
        appliesDaily = true;
    } else if (dailyEnd > dailyBegin) {
        // Interval does not span midnight
        appliesDaily = ((hour >= dailyBegin) && (hour <= dailyEnd));
    } else {
        // Interval spans midnight
        appliesDaily = ((hour >= dailyBegin) || (hour <= dailyEnd));
    }

    return (appliesWeekly && appliesDaily);
}

From source file:org.powertac.common.Tariff.java

License:Apache License

private int getTimeIndex(Instant when) {
    DateTime dt = new DateTime(when, DateTimeZone.UTC);
    int di = dt.getHourOfDay();
    if (isWeekly)
        di += 24 * (dt.getDayOfWeek() - 1);
    return di;/*from ww  w.  ja v a2 s  .  co m*/
}

From source file:org.powertac.factoredcustomer.TimeseriesGenerator.java

License:Apache License

private double generateNextArima101x101(int timeslot) {
    /** R code//from w ww. j a v  a 2  s .  c om
    boostTimeSeries = function(Xt, lambda, t, N, Xht, Xdt, gamma) {
    return (Xt + (lambda * ((log(t-26))^2/(log(N-26))^2) * ((1 - gamma) * Xht + gamma * Xdt)))
    }
    for (t in compRange) {                  
    Zf[t] = Y0 + Yd[D[t]] + Yh[H[t]] + phi1 * Zf[t-1] + Phi1 * Zf[t-24] #+ rnorm(1, 0, sigma^2) + 
                  theta1 * (Zf[t-1] - Zf[t-2]) + Theta1 * (Zf[t-24] - Zf[t-25]) + 
                  theta1 * Theta1 * (Zf[t-25] - Zf[t-26]) 
    Zbf[t] = boostTimeSeries(Zf[t], lambda, t, N, Yh[H[t]], Yd[D[t]], gamma) #+ rnorm(1, 0, sigma^2)
    }
    **/

    DateTime now = service.getTimeslotRepo().getTimeForIndex(timeslot).toDateTime();
    int day = now.getDayOfWeek(); // 1=Monday, 7=Sunday
    int hour = now.getHourOfDay(); // 0-23

    int t = timeslot;

    double logNext = Y0 + Yd[day - 1] + Yh[hour] + phi1 * getLog(t - 1) + Phi1 * getLog(t - 24)
            + theta1 * (getLog(t - 1) - getLog(t - 2)) + Theta1 * (getLog(t - 24) - getLog(t - 25))
            + theta1 * Theta1 * (getLog(t - 25) - getLog(t - 26));
    logNext = logNext + (lambda * (Math.pow(Math.log(t - 26), 2) / Math.pow(Math.log(FORECAST_HORIZON - 26), 2))
            * ((1 - gamma) * Yh[hour] + gamma * Yd[day - 1]));
    logNext = logNext + Math.pow(sigma, 2) * arimaNoise.nextGaussian();
    double next = Math.exp(logNext);
    if (Double.isNaN(next))
        throw new Error("Generated NaN as next time series element!");
    return next;
}

From source file:org.powertac.genco.MisoBuyer.java

License:Apache License

public void init(BrokerProxy proxy, int seedId, ContextService service) {
    log.info("init(" + seedId + ") " + getUsername());
    timeslotsOpen = Competition.currentCompetition().getTimeslotsOpen();
    this.brokerProxyService = proxy;
    //this.service = service;
    this.timeslotRepo = (TimeslotRepo) service.getBean("timeslotRepo");
    this.weatherReportRepo = (WeatherReportRepo) service.getBean("weatherReportRepo");
    this.weatherForecastRepo = (WeatherForecastRepo) service.getBean("weatherForecastRepo");
    RandomSeedRepo randomSeedRepo = (RandomSeedRepo) service.getBean("randomSeedRepo");
    // set up the random generator
    this.tsSeed = randomSeedRepo.getRandomSeed(MisoBuyer.class.getName(), seedId, "ts");
    // compute offsets for daily and weekly seasonal data
    int ts = timeslotRepo.currentSerialNumber();
    timeslotOffset = ts;//from   w ww  . j  a va 2 s  .c o  m
    DateTime start = timeslotRepo.getDateTimeForIndex(ts);
    dailyOffset = start.getHourOfDay();
    weeklyOffset = (start.getDayOfWeek() - 1) * 24 + dailyOffset;
    timeseries = new ComposedTS();
    timeseries.initialize(ts);
}

From source file:org.projectbuendia.client.ui.chart.LocalizedChartDataGridAdapter.java

License:Apache License

private String toColumnId(DateTime dateTime) {
    int hour = dateTime.getHourOfDay() >= 12 ? 12 : 0; // choose am or pm column
    return dateTime.withTimeAtStartOfDay().withHourOfDay(hour).toString();
}

From source file:org.rhq.metrics.simulator.Simulator.java

License:Open Source License

/**
 * Run a sequential simulation where metrics insertion and aggregation run
 * in a single thread in sequence. The progression of time
 * is managed by the simulation. This guarantees that
 * the number of insertions and sequence of events takes
 * place in order irrespective of host limitations.
 *//*  w w w  .  ja v  a2s . c o  m*/
private void runSequentialSimulation(SimulationPlan plan) throws Throwable {
    this.initializeMetricsServer(plan);

    Random random = new Random();
    long timestamp = plan.getDateTimeService().nowInMillis();
    long endOfSimulation = timestamp + 24L * 60 * 60 * 1000 * plan.getSimulationTime();
    int numberOfMetrics = plan.getBatchSize() * plan.getNumMeasurementCollectors();

    Set<MeasurementDataNumeric> data = new HashSet<MeasurementDataNumeric>(plan.getBatchSize());

    int lastAggregationHour = new DateTime(timestamp).getHourOfDay();

    for (; timestamp < endOfSimulation; timestamp += 30 * 1000) {
        DateTime currentTime = new DateTime(timestamp);

        data.clear();
        for (int i = 0; i < numberOfMetrics; ++i) {
            data.add(new MeasurementDataNumeric(timestamp, i, random.nextDouble()));
        }

        WaitForRawInserts waitForRawInserts = new WaitForRawInserts(data.size());
        metricsServer.addNumericData(data, waitForRawInserts);
        waitForRawInserts.await("Failed to insert raw data at time: " + timestamp);

        if (currentTime.getHourOfDay() != lastAggregationHour) {
            lastAggregationHour = currentTime.getHourOfDay();
            metricsServer.calculateAggregates();
        }
    }

    metricsServer.shutdown();
    log.info("Simulation has completed. Initiating shutdown...");
    shutdown(0);
}