Example usage for org.joda.time Period plusHours

List of usage examples for org.joda.time Period plusHours

Introduction

In this page you can find the example usage for org.joda.time Period plusHours.

Prototype

public Period plusHours(int hours) 

Source Link

Document

Returns a new period plus the specified number of hours added.

Usage

From source file:com.planyourexchange.utils.DateUtils.java

License:Open Source License

public static Period sum(Period timeTotal, LocalTime... locatimes) {
    for (LocalTime time : locatimes) {
        timeTotal = timeTotal.plusHours(time.getHourOfDay());
        timeTotal = timeTotal.plusMinutes(time.getMinuteOfHour());
        timeTotal = timeTotal.plusSeconds(time.getSecondOfMinute());
    }// w w  w.j  a v a2s  .  co  m
    return timeTotal;
}

From source file:org.apereo.portlet.hr.timereporting.util.TimeCalculations.java

License:Apache License

/**
 * Utility method to accept a Period and returns a new period that added the time-worked amount in the form
 * of hh:mm and returns a new Period./*from  w  w w.ja  va2  s.  c  om*/
 *
 * @param total
 * @param timeWorked
 * @return
 */
public static Period addTime(Period total, String timeWorked) {
    Period updatedTotal = total;
    if (StringUtils.isNotBlank(timeWorked)) {
        boolean error = false;
        String[] values = timeWorked.split(":");
        if (values.length == 2) {
            try {
                int hours = Integer.parseInt(values[0]);
                int minutes = Integer.parseInt(values[1]);
                updatedTotal = total.plusHours(hours).plusMinutes(minutes);
            } catch (NumberFormatException e) {
                error = true;
            }
        } else {
            error = true;
        }
        if (error) {
            throw new HrPortletRuntimeException("Invalid Time entry not HH:MM, was '" + timeWorked);
        }
    }
    return updatedTotal;
}

From source file:org.jevis.application.unit.SampleRateNode.java

License:Open Source License

private void setPeriod(TextField field) {
    Period newPeriod = Period.ZERO;

    if (sliderMinutes.getValue() != 0) {
        newPeriod = newPeriod.plusMinutes((int) sliderMinutes.getValue());
    }/*  www.ja v  a  2s.c o  m*/
    if (sliderSecounds.getValue() != 0) {
        newPeriod = newPeriod.plusSeconds((int) sliderSecounds.getValue());
    }
    if (sliderHours.getValue() != 0) {
        newPeriod = newPeriod.plusHours((int) sliderHours.getValue());
    }
    if (sliderMonth.getValue() != 0) {
        newPeriod = newPeriod.plusMonths((int) sliderMonth.getValue());
    }
    if (sliderWeek.getValue() != 0) {
        newPeriod = newPeriod.plusWeeks((int) sliderWeek.getValue());
    }

    field.setText(newPeriod.toString());
    _returnPeriod = newPeriod;
}

From source file:voldemort.store.readonly.mr.utils.HadoopUtils.java

License:Apache License

public static Period parsePeriod(String periodStr) {
    Matcher monthsFormat = Pattern.compile("[0-9][0-9]*M").matcher(periodStr);
    Matcher daysFormat = Pattern.compile("[0-9][0-9]*d").matcher(periodStr);
    Matcher hoursFormat = Pattern.compile("[0-9][0-9]*h").matcher(periodStr);
    Matcher minutesFormat = Pattern.compile("[0-9][0-9]*m").matcher(periodStr);

    Period period = new Period();
    while (monthsFormat.find()) {
        period = period.plusMonths(/*from  w w w  . jav a2  s . c  o m*/
                Integer.parseInt(monthsFormat.group().substring(0, monthsFormat.group().length() - 1)));
    }
    while (daysFormat.find()) {
        period = period
                .plusDays(Integer.parseInt(daysFormat.group().substring(0, daysFormat.group().length() - 1)));
    }
    while (hoursFormat.find()) {
        period = period.plusHours(
                Integer.parseInt(hoursFormat.group().substring(0, hoursFormat.group().length() - 1)));
    }
    while (minutesFormat.find()) {
        period = period.plusMinutes(
                Integer.parseInt(minutesFormat.group().substring(0, minutesFormat.group().length() - 1)));
    }

    return period;
}