Example usage for org.joda.time Period getSeconds

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

Introduction

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

Prototype

public int getSeconds() 

Source Link

Document

Gets the seconds field part of the period.

Usage

From source file:org.trakhound.www.trakhound.DeviceDetails.java

License:Open Source License

private void updateDevicePercentages(DeviceStatus status) {

    // Percentages
    if (status.timersInfo != null && status.timersInfo.total > 0) {

        TimersInfo info = status.timersInfo;

        double active = (info.active / info.total) * 100;
        double idle = (info.idle / info.total) * 100;
        double alert = (info.alert / info.total) * 100;

        // Progress Bars

        // Active
        ProgressBar pb = (ProgressBar) findViewById(R.id.ActiveProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(active));

        // Idle/*from   w  w  w  . ja v  a2s  . c  om*/
        pb = (ProgressBar) findViewById(R.id.IdleProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(idle));

        // Alert
        pb = (ProgressBar) findViewById(R.id.AlertProgressBar);
        if (pb != null)
            pb.setProgress((int) Math.round(alert));

        // Percentage TextViews

        // Active
        TextView txt = (TextView) findViewById(R.id.ActivePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", active));

        // Idle
        txt = (TextView) findViewById(R.id.IdlePercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", idle));

        // Alert
        txt = (TextView) findViewById(R.id.AlertPercentage);
        if (txt != null)
            txt.setText(String.format("%.0f%%", alert));

        // Time Elapsed TextViews

        // Active
        Integer seconds = Integer.valueOf((int) Math.round(info.active));
        Period period = new Period(seconds * 1000);
        String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.ActiveTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Idle
        seconds = Integer.valueOf((int) Math.round(info.idle));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.IdleTime);
        if (txt != null)
            txt.setText(statusPeriod);

        // Alert
        seconds = Integer.valueOf((int) Math.round(info.alert));
        period = new Period(seconds * 1000);
        statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                period.getSeconds());
        txt = (TextView) findViewById(R.id.AlertTime);
        if (txt != null)
            txt.setText(statusPeriod);

    } else
        clearDevicePercentages();
}

From source file:org.trakhound.www.trakhound.device_list.ListAdapter.java

License:Open Source License

private void setProductionStatus(ViewHolder holder, StatusInfo info) {

    if (info != null && info.deviceStatus != null) {

        if (holder.ProductionStatus != null)
            holder.ProductionStatus.setText(info.deviceStatus);

        if (holder.ProductionStatusTimer != null && info.deviceStatusTimer != null) {

            Period period = new Period(info.deviceStatusTimer * 1000);
            String statusPeriod = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(),
                    period.getSeconds());

            holder.ProductionStatusTimer.setText(statusPeriod);
        }//from  www  .j a  v a2s .  c  o  m
    }
}

From source file:org.wisdom.akka.impl.Job.java

License:Apache License

/**
 * Translates the given (Joda) Period to (Scala) duration.
 *
 * @param period the period/*  w  w w  .j av a2s .com*/
 * @return the duration representing the same amount of time
 */
public static FiniteDuration toDuration(Period period) {
    return Duration.create(period.getDays(), TimeUnit.DAYS)
            .plus(Duration.create(period.getHours(), TimeUnit.HOURS)
                    .plus(Duration.create(period.getMinutes(), TimeUnit.MINUTES)
                            .plus(Duration.create(period.getSeconds(), TimeUnit.SECONDS))));
}

From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java

License:Open Source License

/**
 * This method is used to get the breakdown of the duration between 2 days/timestamps in terms of years,
 * months, days, hours, minutes and seconds
 *
 * @param fromDate Start timestamp of the duration
 * @param toDate   End timestamp of the duration
 * @return A map containing the breakdown
 * @throws APIMgtUsageQueryServiceClientException when there is an error during date parsing
 *///from w  ww . j a va 2s. c o  m
private Map<String, Integer> getDurationBreakdown(String fromDate, String toDate)
        throws APIMgtUsageQueryServiceClientException {
    Map<String, Integer> durationBreakdown = new HashMap<String, Integer>();

    DateTimeFormatter formatter = DateTimeFormat
            .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN);
    LocalDateTime startDate = LocalDateTime.parse(fromDate, formatter);
    LocalDateTime endDate = LocalDateTime.parse(toDate, formatter);
    Period period = new Period(startDate, endDate);
    int numOfYears = period.getYears();
    int numOfMonths = period.getMonths();
    int numOfWeeks = period.getWeeks();
    int numOfDays = period.getDays();
    if (numOfWeeks > 0) {
        numOfDays += numOfWeeks * 7;
    }
    int numOfHours = period.getHours();
    int numOfMinutes = period.getMinutes();
    int numOfSeconds = period.getSeconds();
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_YEARS, numOfYears);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MONTHS, numOfMonths);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_DAYS, numOfDays);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_WEEKS, numOfWeeks);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_HOURS, numOfHours);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MINUTES, numOfMinutes);
    durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_SECONDS, numOfSeconds);
    return durationBreakdown;
}

From source file:uk.ac.susx.tag.method51.core.params.codec.concrete.DurationCodec.java

License:Apache License

@Override
public Duration decodeString(String value) throws DecodeException {
    Duration result = null;//from  ww w  . j a v  a 2 s . co m

    long milliseconds;

    try {
        milliseconds = Long.parseLong(value);

    } catch (NumberFormatException e) {

        try {
            if (value.length() == 0) {
                throw new IllegalArgumentException("zero length interval specification");
            }
            value = value.toUpperCase();

            if (!value.matches(".*[DWMHS].*")) {
                throw new IllegalArgumentException(
                        "no time units specified, see ISO 8601 duration specification (months / years not supported): http://en.wikipedia.org/wiki/ISO_8601#Durations");
            }

            if (!value.startsWith("P")) {
                value = "P" + value;
            }

            Matcher m = Pattern.compile("[HMS]").matcher(value);
            if (!value.contains("T") && m.find()) {
                String c = m.group(0);
                int i = value.indexOf(c);
                value = value.substring(0, i - 1) + "T" + value.substring(i - 1);
            }

            Period period = ISOPeriodFormat.standard().parsePeriod(value);
            long seconds = 0;
            seconds += period.getSeconds();
            seconds += period.getMinutes() * DateTimeConstants.SECONDS_PER_MINUTE;
            seconds += period.getHours() * DateTimeConstants.SECONDS_PER_HOUR;
            seconds += period.getDays() * DateTimeConstants.SECONDS_PER_DAY;
            seconds += period.getWeeks() * DateTimeConstants.SECONDS_PER_WEEK;

            milliseconds = seconds * 1000;

        } catch (IllegalArgumentException e1) {
            throw new DecodeException("'" + value + "' is not a number, or an ISO 8601 duration", e1);
        }
    }

    result = new Duration(milliseconds);

    return result;
}

From source file:utilities.time.DateAndTimes.java

License:Open Source License

/**
 *
 * This will calculate out and return a String the length of a period in easy to read format: Y
 *
 * @param duration/*from   w ww.  j ava 2 s. c o  m*/
 * @param yearsSeparatorFormat
 * @param monthsSeparatorFormat
 * @param weeksSeparatorFormat
 * @param daysSeparatorFormat
 * @param hoursSeparatorFormat
 * @param minutesSeparatorFormat
 * @param secondsSeparatorFormat
 * @return
 */
public static String getPeriodFormattedFromMilliseconds(long duration, String yearsSeparatorFormat,
        String monthsSeparatorFormat, String weeksSeparatorFormat, String daysSeparatorFormat,
        String hoursSeparatorFormat, String minutesSeparatorFormat, String secondsSeparatorFormat) {
    Period period = new Period(duration);
    if (period.getYears() > 0) {
        return getPeriodFormat(period, yearsSeparatorFormat, monthsSeparatorFormat, weeksSeparatorFormat,
                daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getMonths() > 0) {
        return getPeriodFormat(period, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat,
                hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getWeeks() > 0) {
        return getPeriodFormat(period, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat,
                minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getDays() > 0) {
        return getPeriodFormat(period, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat,
                secondsSeparatorFormat);
    } else if (period.getHours() > 0) {
        return getPeriodFormat(period, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getMinutes() > 0) {
        return getPeriodFormat(period, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getSeconds() > 0) {
        return getPeriodFormat(period, secondsSeparatorFormat);
    } else {
        return null;
    }
}