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.jasig.portlet.blackboardvcportlet.service.SessionForm.java

License:Apache License

public void setStartTime(DateTime startTime) {
    startDate = startTime.toDateMidnight();
    startHour = startTime.getHourOfDay();
    startMinute = startTime.getMinuteOfHour();
    startHourMinute = new LocalTime(startTime);
}

From source file:org.jasig.portlet.blackboardvcportlet.service.SessionForm.java

License:Apache License

public void setEndTime(DateTime endTime) {
    endDate = endTime.toDateMidnight();/*from  w ww .j a  va 2 s  .  c o  m*/
    endHour = endTime.getHourOfDay();
    endMinute = endTime.getMinuteOfHour();
    endHourMinute = new LocalTime(endTime);
}

From source file:org.jasig.portlet.calendar.adapter.ExchangeCalendarAdapter.java

License:Apache License

/**
 * Get an XMLGregorianCalendar for the specified date.
 *
 * @param date/*from   w  w w  .  jav a2 s  .com*/
 * @return
 * @throws DatatypeConfigurationException
 */
protected XMLGregorianCalendar getXmlDate(DateTime date) throws DatatypeConfigurationException {
    // construct an XMLGregorianCalendar
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar start = datatypeFactory.newXMLGregorianCalendar();
    start.setYear(date.getYear());
    start.setMonth(date.getMonthOfYear());
    start.setTime(date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(),
            date.getMillisOfSecond());
    start.setDay(date.getDayOfMonth());
    return start;
}

From source file:org.jbpm.designer.web.server.SimulationServlet.java

License:Apache License

private String getDateString(long seDate) {
    Date d = new Date(seDate);
    DateTime dt = new DateTime(seDate);
    StringBuffer retBuf = new StringBuffer();
    retBuf.append(dt.getYear()).append(",");
    retBuf.append(dt.getMonthOfYear()).append(",");
    retBuf.append(dt.getDayOfMonth()).append(",");
    retBuf.append(dt.getHourOfDay()).append(",");
    retBuf.append(dt.getMinuteOfHour()).append(",");
    retBuf.append(dt.getSecondOfMinute()).append(",");
    retBuf.append(dt.getMillisOfSecond());
    return retBuf.toString();
}

From source file:org.jgrasstools.hortonmachine.modules.hydrogeomorphology.etp.OmsPresteyTaylorEtpModel.java

License:Open Source License

@Execute
public void process() throws Exception {
    checkNull(inTemp);/*from   www . j a  va2 s  . com*/

    outPTEtp = new HashMap<Integer, double[]>();
    Set<Entry<Integer, double[]>> entrySet = inTemp.entrySet();
    for (Entry<Integer, double[]> entry : entrySet) {
        Integer basinId = entry.getKey();

        double temp = defaultTemp;
        double t = entry.getValue()[0];
        if (!isNovalue(t)) {
            temp = t;
        }

        double netradiation = 0;
        if (doHourly == true) {
            netradiation = defaultHourlyNetradiation * 0.0864 / 24.0;
        } else {
            netradiation = defaultDailyNetradiation * 0.0864;
        }
        if (inNetradiation != null) {
            double n = inNetradiation.get(basinId)[0];
            if (!isNovalue(n)) {
                if (doHourly == true) {
                    netradiation = n * 0.0864 / 24.0;
                } else {
                    netradiation = n * 0.0864;
                }
            }
        }

        double pressure = defaultPressure;
        if (inPressure != null) {
            double p = inPressure.get(basinId)[0];
            if (isNovalue(p)) {
                pressure = defaultPressure;
            } else {
                pressure = p;
            }
        }

        DateTime currentDatetime = formatter.parseDateTime(tCurrent);
        int ora = currentDatetime.getHourOfDay();
        boolean isLigth = false;
        if (ora > 6 && ora < 18) {
            isLigth = true;
        }

        double etp = compute(pGmorn, pGnight, pAlpha, netradiation, temp, pressure, isLigth, doHourly);
        outPTEtp.put(basinId, new double[] { etp });
    }
}

From source file:org.jimcat.services.rename.Renamer.java

License:Open Source License

@SuppressWarnings("null")
private String getNewName(Image image, int n) {
    String newName = configString;
    DateTime date = null;

    switch (useDate) {
    case MODIFICATION:
        date = image.getMetadata().getModificationDate();
        break;//ww  w .j  a  va 2s .c  om
    case ADDED:
        date = image.getMetadata().getDateAdded();
        break;
    case TAKEN:

        ExifMetadata exifMetadata = image.getExifMetadata();

        if (exifMetadata != null) {
            date = exifMetadata.getDateTaken();
        }
        break;
    }

    String random;

    do {
        random = String.valueOf(Math.random());
    } while (configString.contains(random));

    if (hasParameter(escapeCharacter.charAt(0))) {
        newName = newName.replace(escapeCharacter + escapeCharacter, random);
    }

    if (hasParameter('n')) {
        String number = String.format("%0" + digits + "d", new Integer(n));
        newName = newName.replace(escapeCharacter + "n", number);
    }

    if (hasParameter('w')) {
        newName = newName.replace(escapeCharacter + "w", "" + image.getMetadata().getWidth());
    }

    if (hasParameter('h')) {
        newName = newName.replace(escapeCharacter + "h", "" + image.getMetadata().getHeight());
    }

    if (hasParameter('d')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "d", unknownResultCharacter);
        } else {
            String day = formatNumber(date.getDayOfMonth(), 2);
            newName = newName.replace(escapeCharacter + "d", day);
        }
    }

    if (hasParameter('m')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "m", unknownResultCharacter);
        } else {
            String month = formatNumber(date.getMonthOfYear(), 2);
            newName = newName.replace(escapeCharacter + "m", month);
        }
    }

    if (hasParameter('y')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "y", unknownResultCharacter);
        } else {
            String year = formatNumber(date.getYear(), 4);
            newName = newName.replace(escapeCharacter + "y", year);
        }
    }

    if (hasParameter('H')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "H", unknownResultCharacter);
        } else {
            String hour = formatNumber(date.getHourOfDay(), 2);
            newName = newName.replace(escapeCharacter + "H", hour);
        }
    }

    if (hasParameter('M')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "M", unknownResultCharacter);
        } else {
            String minute = formatNumber(date.getMinuteOfHour(), 2);
            newName = newName.replace(escapeCharacter + "M", minute);
        }
    }

    if (hasParameter('S')) {
        if (date == null) {
            newName = newName.replace(escapeCharacter + "S", unknownResultCharacter);
        } else {
            String seconds = formatNumber(date.getSecondOfMinute(), 2);
            newName = newName.replace(escapeCharacter + "S", seconds);
        }
    }

    if (hasParameter('r')) {
        newName = newName.replace(escapeCharacter + "r", ratingToString(image.getRating()));
    }

    if (hasParameter('f')) {
        if (image.getMetadata() != null && image.getMetadata().getPath() != null) {
            String fileName = removeFileType(image.getMetadata().getPath());
            newName = newName.replace(escapeCharacter + "f", fileName);
        } else {
            newName = newName.replace(escapeCharacter + "f", unknownResultCharacter);
        }
    }

    if (newName.length() == 0) {
        return newName;
    }

    // if the user is just typing dont show the last $
    // but if he wants a $ at the and (by using $$) allow it and even allow
    // $$ at the end

    int escapeCharactersAtEnd = 0;
    int index = newName.length() - 1;

    while (index >= 0 && newName.charAt(index--) == escapeCharacter.charAt(0)) {
        escapeCharactersAtEnd++;
    }

    if (escapeCharactersAtEnd % 2 == 1) {
        newName = newName.substring(0, newName.length() - 1);
    }

    if (hasParameter(escapeCharacter.charAt(0))) {
        newName = newName.replace(random, escapeCharacter);
    }

    // set at the end because the original title could contain evil control
    // sequences
    if (hasParameter('t')) {
        newName = newName.replace(escapeCharacter + "t", image.getTitle());
    }

    return newName;
}

From source file:org.jmxtrans.embedded.samples.graphite.CocktailAppMetricsSimulator.java

License:Open Source License

public void generateLoad(GraphiteDataInjector graphiteDataInjector) throws Exception {

    TimeSeries rawIntegratedTimeSeries = new TimeSeries("sales.integrated.raw");
    TimeSeries rawTimeSeries = new TimeSeries("sales.raw");

    DateTime now = new DateTime();
    DateTime end = now.plusDays(3);//from   w  ww.jav a 2s.  com

    DateTime date = now.minusDays(15);
    DateTime twoDaysAfterBegin = date.plusDays(2);
    double serverFairness = 1.05;

    int integratedValue = 0;

    MathContext mathContext = new MathContext(1, RoundingMode.CEILING);

    int randomFactor = 0;

    while (date.isBefore(end)) {
        if (rawIntegratedTimeSeries.getItemCount() % 120 == 0) {
            randomFactor = 10 + random.nextInt(2);
        }
        int weekGrowthFactor = 6 - (now.getWeekOfWeekyear() - date.getWeekOfWeekyear());
        int value = new BigDecimal(randomFactor) // random factor
                .multiply(new BigDecimal(10)) // go to cents of USD
                .multiply(new BigDecimal(weekGrowthFactor))
                .multiply(new BigDecimal(hourlyDistribution[date.getHourOfDay()]))
                .multiply(new BigDecimal(weeklyDistribution[date.getDayOfWeek()]))
                .divide(new BigDecimal(20), mathContext).intValue(); // split hourly value in minutes

        integratedValue += value;
        for (int i1 = 0; i1 < 3; i1++) {
            Second period = new Second(date.toDate());
            rawTimeSeries.add(period, value);
            rawIntegratedTimeSeries.add(period, integratedValue);
            date = date.plusSeconds(30);
        }
    }

    rawIntegratedTimeSeries = MovingAverage.createMovingAverage(rawIntegratedTimeSeries,
            rawIntegratedTimeSeries.getKey().toString(), 60 * 7, 0);
    rawTimeSeries = MovingAverage.createMovingAverage(rawTimeSeries, rawTimeSeries.getKey().toString(), 60 * 7,
            0);

    // SALES - REVENUE

    TimeSeries salesRevenueInCentsCounter = new TimeSeries("sales.revenueInCentsCounter");
    TimeSeries salesRevenueInCentsCounterSrv1 = new TimeSeries("srv1.sales.revenueInCentsCounter");
    TimeSeries salesRevenueInCentsCounterSrv2 = new TimeSeries("srv2.sales.revenueInCentsCounter");
    int resetValue2ToZeroOffset = 0; // reset value 2 after 3 days of metrics
    for (int i = 0; i < rawIntegratedTimeSeries.getItemCount(); i++) {
        TimeSeriesDataItem dataItem = rawIntegratedTimeSeries.getDataItem(i);
        int value = dataItem.getValue().intValue();
        // value1 is 5% higher to value2 due to a 'weirdness' in the load balancing
        int value1 = Math.min((int) (value * serverFairness / 2), value);

        {
            // simulate srv2 restart
            DateTime currentDate = new DateTime(dataItem.getPeriod().getStart());
            boolean shouldResetValue2 = resetValue2ToZeroOffset == 0
                    && currentDate.getDayOfYear() == twoDaysAfterBegin.getDayOfYear();
            if (shouldResetValue2) {
                resetValue2ToZeroOffset = value - value1;
                System.out.println("reset value2 of " + resetValue2ToZeroOffset + " at " + currentDate);
            }
        }

        int value2 = value - value1 - resetValue2ToZeroOffset;
        salesRevenueInCentsCounter.add(dataItem.getPeriod(), value);
        salesRevenueInCentsCounterSrv1.add(dataItem.getPeriod(), value1);
        salesRevenueInCentsCounterSrv2.add(dataItem.getPeriod(), value2);
    }
    graphiteDataInjector.exportMetrics(salesRevenueInCentsCounter, salesRevenueInCentsCounterSrv1,
            salesRevenueInCentsCounterSrv2);

    // SALES - ITEMS
    TimeSeries salesItemsCounter = new TimeSeries("sales.itemsCounter");
    TimeSeries salesItemsCounterSrv1 = new TimeSeries("srv1.sales.itemsCounter");
    TimeSeries salesItemsCounterSrv2 = new TimeSeries("srv2.sales.itemsCounter");

    for (int i = 0; i < rawIntegratedTimeSeries.getItemCount(); i++) {
        RegularTimePeriod period = salesRevenueInCentsCounter.getDataItem(i).getPeriod();
        int ordersPriceInCents1 = salesRevenueInCentsCounterSrv1.getDataItem(i).getValue().intValue();
        int ordersPriceInCents2 = salesRevenueInCentsCounterSrv2.getDataItem(i).getValue().intValue();

        int value1 = ordersPriceInCents1 / 600;
        int value2 = ordersPriceInCents2 / 600;

        salesItemsCounter.add(period, value1 + value2);
        salesItemsCounterSrv1.add(period, value1);
        salesItemsCounterSrv2.add(period, value2);

    }

    graphiteDataInjector.exportMetrics(salesItemsCounter, salesItemsCounterSrv1, salesItemsCounterSrv2);

    // WEBSITE - VISITORS
    TimeSeries newVisitorsCounterSrv1 = new TimeSeries("srv1.website.visitors.newVisitorsCounter");
    TimeSeries newVisitorsCounterSrv2 = new TimeSeries("srv1.website.visitors.newVisitorsCounter");

    TimeSeries activeVisitorsGaugeSrv1 = new TimeSeries("srv1.website.visitors.activeGauge");
    TimeSeries activeVisitorsGaugeSrv2 = new TimeSeries("srv2.website.visitors.activeGauge");
    int integratedValue1 = 0;
    int integratedValue2 = 0;
    float activeVisitorsFactor = 1;
    for (int i = 0; i < rawTimeSeries.getItemCount(); i++) {

        TimeSeriesDataItem dataItem = rawTimeSeries.getDataItem(i);
        RegularTimePeriod period = dataItem.getPeriod();
        int value = dataItem.getValue().intValue() / 20;
        integratedValue += value;

        int value1 = Math.min((int) (value * serverFairness / 2), value);
        integratedValue1 += value1;

        int value2 = value - value1;
        integratedValue2 += value2;

        newVisitorsCounterSrv1.add(period, integratedValue1);
        newVisitorsCounterSrv2.add(period, integratedValue2);

        if (i % 120 == 0) {
            activeVisitorsFactor = (10 + random.nextInt(3)) / 10;
        }

        activeVisitorsGaugeSrv1.add(period, Math.floor(value1 * activeVisitorsFactor));
        activeVisitorsGaugeSrv2.add(period, Math.floor(value2 * activeVisitorsFactor));
    }

    graphiteDataInjector.exportMetrics(newVisitorsCounterSrv1, newVisitorsCounterSrv2, activeVisitorsGaugeSrv1,
            activeVisitorsGaugeSrv2);

}

From source file:org.jmxtrans.samples.graphite.GraphiteDataInjector.java

License:Open Source License

public void generateLoad() throws Exception {
    System.out.println("Inject data on Graphite server " + this.graphiteHost);

    TimeSeries timeSeries = new TimeSeries("shopping-cart.raw");

    DateTime now = new DateTime();
    DateTime end = now.plusDays(1);// ww w.j a  v a2  s  .  c om

    DateTime date = now.minusDays(15);
    DateTime twoDaysAfterBegin = date.plusDays(2);

    int integratedValue = 0;

    MathContext mathContext = new MathContext(1, RoundingMode.CEILING);

    int randomFactor = 0;

    while (date.isBefore(end)) {
        if (timeSeries.getItemCount() % 120 == 0) {
            randomFactor = 10 + random.nextInt(2);
        }
        int weekGrowthFactor = 6 - (now.getWeekOfWeekyear() - date.getWeekOfWeekyear());
        int value = new BigDecimal(randomFactor) // random factor
                .multiply(new BigDecimal(10)) // go to cents of USD
                .multiply(new BigDecimal(weekGrowthFactor))
                .multiply(new BigDecimal(hourlyDistribution[date.getHourOfDay()]))
                .multiply(new BigDecimal(weeklyDistribution[date.getDayOfWeek()]))
                .divide(new BigDecimal(20), mathContext).intValue(); // split hourly value in minutes

        integratedValue += value;
        for (int i1 = 0; i1 < 3; i1++) {
            timeSeries.add(new Minute(date.toDate()), integratedValue);
            date = date.plusMinutes(1);
        }
    }

    TimeSeries ordersPriceInCentsTimeSeries = MovingAverage.createMovingAverage(timeSeries,
            "shopping-cart.OrdersPriceInCents", 60 * 7, 0);

    TimeSeries ordersPriceInCentsSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrdersPriceInCents");
    TimeSeries ordersPriceInCentsSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrdersPriceInCents");
    int resetValue2ToZeroOffset = 0; // reset value 2 after 3 days of metrics
    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        TimeSeriesDataItem dataItem = ordersPriceInCentsTimeSeries.getDataItem(i);
        int value = dataItem.getValue().intValue();
        // value1 is 5% higher to value2 due to a 'weirdness' in the load balancing
        int value1 = Math.min((int) (value * 1.05 / 2), value);

        {
            // simulate srv2 restart
            DateTime currentDate = new DateTime(dataItem.getPeriod().getStart());
            boolean shouldResetValue2 = resetValue2ToZeroOffset == 0
                    && currentDate.getDayOfYear() == twoDaysAfterBegin.getDayOfYear();
            if (shouldResetValue2) {
                resetValue2ToZeroOffset = value - value1;
                System.out.println("reset value2 of " + resetValue2ToZeroOffset + " at " + currentDate);
            }
        }

        int value2 = value - value1 - resetValue2ToZeroOffset;
        // System.out.println("value=" + value + ", value1=" + value1 + ", value2=" + value2);
        ordersPriceInCentsSrv1TimeSeries.add(dataItem.getPeriod(), value1);
        ordersPriceInCentsSrv2TimeSeries.add(dataItem.getPeriod(), value2);
    }

    TimeSeries orderItemsCountTimeSeries = new TimeSeries("shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv1TimeSeries = new TimeSeries("srv1.shopping-cart.OrderItemsCount");
    TimeSeries orderItemsCountSrv2TimeSeries = new TimeSeries("srv2.shopping-cart.OrderItemsCount");

    for (int i = 0; i < ordersPriceInCentsTimeSeries.getItemCount(); i++) {
        RegularTimePeriod period = ordersPriceInCentsTimeSeries.getDataItem(i).getPeriod();
        int ordersPriceInCents1 = ordersPriceInCentsSrv1TimeSeries.getDataItem(i).getValue().intValue();
        int ordersPriceInCents2 = ordersPriceInCentsSrv2TimeSeries.getDataItem(i).getValue().intValue();

        int value1 = ordersPriceInCents1 / 600;
        int value2 = ordersPriceInCents2 / 600;

        orderItemsCountTimeSeries.add(period, value1 + value2);
        orderItemsCountSrv1TimeSeries.add(period, value1);
        orderItemsCountSrv2TimeSeries.add(period, value2);

    }

    exportMetrics(ordersPriceInCentsTimeSeries, ordersPriceInCentsSrv1TimeSeries,
            ordersPriceInCentsSrv2TimeSeries, ordersPriceInCentsTimeSeries, orderItemsCountTimeSeries,
            orderItemsCountSrv1TimeSeries, orderItemsCountSrv2TimeSeries);

    TimeSeries activeSrv1Visitors = new TimeSeries("srv1.visitors.currentActive");
    TimeSeries activeSrv2Visitors = new TimeSeries("srv1.visitors.currentActive");

}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJodaGetHour() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "getHour");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getHourOfDay();
            if (val == -1) {
                System.out.println("Anti optimise");
            }/* w  ww .j  a  v  a2s .  c  o  m*/
        }
        end(COUNT);
    }
}

From source file:org.joda.example.time.DateTimePerformance.java

License:Apache License

private void checkJISOGetHour() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "getHour");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getHourOfDay();
            if (val == -1) {
                System.out.println("Anti optimise");
            }//  w  w w.j  a v  a 2  s. c  om
        }
        end(COUNT);
    }
}