Example usage for org.joda.time PeriodType time

List of usage examples for org.joda.time PeriodType time

Introduction

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

Prototype

public static PeriodType time() 

Source Link

Document

Gets a type that defines all standard time fields.

Usage

From source file:com.igormaznitsa.jute.Utils.java

License:Apache License

public static String printTimeDelay(final long timeInMilliseconds) {
    final Duration duration = new Duration(timeInMilliseconds);
    final Period period = duration.toPeriod().normalizedStandard(PeriodType.time());
    return TIME_FORMATTER.print(period);
}

From source file:eu.vranckaert.worktime.activities.account.listadapter.SyncHistoryListAdapter.java

License:Apache License

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Log.d(ctx, LOG_TAG, "Start rendering/recycling row " + position);
    View row = null;//  w w  w .  j  a  v  a  2  s. c  om
    final SyncHistory sh = syncHistories.get(position);

    if (convertView == null) {
        Log.d(ctx, LOG_TAG, "Render a new line in the list");
        row = ctx.getLayoutInflater().inflate(R.layout.list_item_sync_histories, parent, false);
    } else {
        Log.d(ctx, LOG_TAG, "Recycling an existing line in the list");
        row = convertView;
    }

    Log.d(ctx, LOG_TAG, "Ready to update the sync history data...");
    TextView started = (TextView) row.findViewById(R.id.account_sync_history_start_time);
    started.setText(DateUtils.DateTimeConverter.convertDateTimeToString(sh.getStarted(), DateFormat.MEDIUM,
            TimeFormat.MEDIUM, ctx));

    String syncDuration = "";
    if (sh.getEnded() != null) {
        syncDuration = DateUtils.TimeCalculator.calculateDuration(ctx, sh.getStarted(), sh.getEnded(),
                PeriodType.time());
    } else {
        syncDuration = DateUtils.TimeCalculator.calculateDuration(ctx, sh.getStarted(), new Date(),
                PeriodType.time());
    }

    TextView duration = (TextView) row.findViewById(R.id.account_sync_history_duration);
    duration.setText(syncDuration);

    TextView result = (TextView) row.findViewById(R.id.account_sync_history_result);
    ImageView resultIcon = (ImageView) row.findViewById(R.id.account_sync_history_result_icon);
    View reasonContainer = row.findViewById(R.id.account_sync_history_reason_container);
    reasonContainer.setVisibility(View.GONE);

    switch (sh.getStatus()) {
    case BUSY:
        resultIcon.setImageDrawable(ctx.getResources().getDrawable(R.drawable.ic_av_download));
        result.setText(ctx.getString(R.string.lbl_account_sync_resolution_busy));
        break;
    case SUCCESSFUL:
        resultIcon.setImageDrawable(ctx.getResources().getDrawable(R.drawable.ic_navigation_accept));
        result.setText(ctx.getString(R.string.lbl_account_sync_resolution_successful));
        break;
    case INTERRUPTED:
        resultIcon.setImageDrawable(ctx.getResources().getDrawable(R.drawable.ic_alerts_and_states_error));
        result.setText(ctx.getString(R.string.lbl_account_sync_resolution_interrupted));

        TextView interruptedReason = (TextView) row.findViewById(R.id.account_sync_history_reason);
        interruptedReason.setText(ctx.getString(R.string.lbl_account_sync_history_reason_interruption));
        reasonContainer.setVisibility(View.VISIBLE);
        break;
    case FAILED:
        resultIcon.setImageDrawable(ctx.getResources().getDrawable(R.drawable.ic_alerts_and_states_error));
        result.setText(ctx.getString(R.string.lbl_account_sync_resolution_failed));

        TextView failureReason = (TextView) row.findViewById(R.id.account_sync_history_reason);
        failureReason.setText(sh.getFailureReason());
        reasonContainer.setVisibility(View.VISIBLE);
        break;
    case TIMED_OUT:
        resultIcon.setImageDrawable(ctx.getResources().getDrawable(R.drawable.ic_device_access_time));
        result.setText(ctx.getString(R.string.lbl_account_sync_resolution_timed_out));
        break;
    }

    Log.d(ctx, LOG_TAG, "Done rendering row " + position);
    return row;
}

From source file:org.apache.pig.Main.java

License:Apache License

private static void printScriptRunTime(DateTime startTime) {
    DateTime endTime = new DateTime();
    Duration duration = new Duration(startTime, endTime);
    Period period = duration.toPeriod().normalizedStandard(PeriodType.time());
    log.info("Pig script completed in " + PeriodFormat.getDefault().print(period) + " (" + duration.getMillis()
            + " ms)");
}

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

License:Apache License

public static String convertPeriodToHHMM(Period period) {
    Period timeStandardized = period.normalizedStandard(PeriodType.time());
    return getDoubleDigit(timeStandardized.getHours()) + ":" + getDoubleDigit(timeStandardized.getMinutes());
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java

License:Apache License

private PeriodType determinePeriodType(String s) {

    PeriodType periodType = PeriodType.standard();

    String current = s;//  w  ww . ja  va 2s .c om

    if (current.startsWith(PeriodType.standard().getName())) {
        periodType = PeriodType.standard();
        current = s.substring(PeriodType.standard().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDayTime().getName())) {
        periodType = PeriodType.yearMonthDayTime();
        current = s.substring(PeriodType.yearMonthDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDay().getName())) {
        periodType = PeriodType.yearMonthDay();
        current = s.substring(PeriodType.yearMonthDay().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDayTime().getName())) {
        periodType = PeriodType.yearWeekDayTime();
        current = s.substring(PeriodType.yearWeekDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDay().getName())) {
        periodType = PeriodType.yearWeekDay();
        current = s.substring(PeriodType.yearWeekDay().getName().length());

    } else if (current.startsWith(PeriodType.yearDayTime().getName())) {
        periodType = PeriodType.yearDayTime();
        current = s.substring(PeriodType.yearDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearDay().getName())) {
        periodType = PeriodType.yearDay();
        current = s.substring(PeriodType.yearDay().getName().length());

    } else if (current.startsWith(PeriodType.dayTime().getName())) {
        periodType = PeriodType.dayTime();
        current = s.substring(PeriodType.dayTime().getName().length());

    } else if (current.startsWith(PeriodType.time().getName())) {
        periodType = PeriodType.time();
        current = s.substring(PeriodType.time().getName().length());

    } else if (current.startsWith(PeriodType.years().getName())) {
        periodType = PeriodType.years();
        current = s.substring(PeriodType.years().getName().length());

    } else if (current.startsWith(PeriodType.months().getName())) {
        periodType = PeriodType.months();
        current = s.substring(PeriodType.months().getName().length());

    } else if (current.startsWith(PeriodType.weeks().getName())) {
        periodType = PeriodType.weeks();
        current = s.substring(PeriodType.weeks().getName().length());

    } else if (current.startsWith(PeriodType.days().getName())) {
        periodType = PeriodType.days();
        current = s.substring(PeriodType.days().getName().length());

    } else if (current.startsWith(PeriodType.hours().getName())) {
        periodType = PeriodType.hours();
        current = s.substring(PeriodType.hours().getName().length());

    } else if (current.startsWith(PeriodType.minutes().getName())) {
        periodType = PeriodType.minutes();
        current = s.substring(PeriodType.minutes().getName().length());

    } else if (current.startsWith(PeriodType.seconds().getName())) {
        periodType = PeriodType.seconds();
        current = s.substring(PeriodType.seconds().getName().length());

    } else if (current.startsWith(PeriodType.millis().getName())) {
        periodType = PeriodType.millis();
        current = s.substring(PeriodType.millis().getName().length());
    }

    while (current.length() > 0) {

        if (current.startsWith("NoYears")) {
            periodType = periodType.withYearsRemoved();
            current = s.substring("NoYears".length());
        } else if (current.startsWith("NoMonths")) {
            periodType = periodType.withMonthsRemoved();
            current = s.substring("NoMonths".length());
        } else if (current.startsWith("NoWeeks")) {
            periodType = periodType.withWeeksRemoved();
            current = s.substring("NoWeeks".length());
        } else if (current.startsWith("NoDays")) {
            periodType = periodType.withDaysRemoved();
            current = s.substring("NoDays".length());
        } else if (current.startsWith("NoHours")) {
            periodType = periodType.withHoursRemoved();
            current = s.substring("NoHours".length());
        } else if (current.startsWith("NoMinutes")) {
            periodType = periodType.withMinutesRemoved();
            current = s.substring("NoMinutes".length());
        } else if (current.startsWith("NoSeconds")) {
            periodType = periodType.withSecondsRemoved();
            current = s.substring("NoSeconds".length());
        } else if (current.startsWith("NoMillis")) {
            periodType = periodType.withMillisRemoved();
            current = s.substring("NoMillis".length());
        } else {
            throw new IllegalArgumentException("Unrecognised PeriodType: " + s + "{" + current + "}");
        }
    }
    return periodType;
}

From source file:org.yamj.common.tools.DateTimeTools.java

License:Open Source License

/**
 * Format the duration in milliseconds in the given format
 *
 * @param milliseconds// w  w w.  j  av a 2s . c o  m
 * @param format
 * @return
 */
public static String formatDuration(long milliseconds, PeriodFormatter format) {
    Period period = new Period(milliseconds, PeriodType.time());
    period = period.normalizedStandard();
    return format.print(period);
}