Java 类org.joda.time.format.PeriodFormatterBuilder 实例源码

项目:Equella    文件:EchoUtils.java   
public static String formatDuration(long duration)
{
    // Using Joda Time
    DateTime now = new DateTime(); // Now
    DateTime plus = now.plus(new Duration(duration * 1000));

    // Define and calculate the interval of time
    Interval interval = new Interval(now.getMillis(), plus.getMillis());
    Period period = interval.toPeriod(PeriodType.time());

    // Define the period formatter for pretty printing
    String ampersand = " & ";
    PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
        .appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
        .appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();

    return pf.print(period).trim();
}
项目:Fahrplan    文件:ConnectionAdapter.java   
private String prettifyDuration(String duration) {
    PeriodFormatter formatter = new PeriodFormatterBuilder()
            .appendDays().appendSuffix("d")
            .appendHours().appendSuffix(":")
            .appendMinutes().appendSuffix(":")
            .appendSeconds().toFormatter();

    Period p = formatter.parsePeriod(duration);

    String day = context.getResources().getString(R.string.day_short);

    if(p.getDays() > 0) {
        return String.format("%d"+ day + " %dh %dm", p.getDays(), p.getHours(), p.getMinutes());
    } else if (p.getHours() > 0) {
        return String.format(Locale.getDefault(), "%dh %dm", p.getHours(), p.getMinutes());
    } else {
        return String.format(Locale.getDefault(), "%dm", p.getMinutes());
    }
}
项目:Biliomi    文件:TimeFormatter.java   
/**
 * Internal method to convert a period of lesser than month scales
 *
 * @param period The period to format
 * @return A relative time string describing the period
 */
private String timeStringSmallScale(Period period) {
  PeriodFormatterBuilder builder = new PeriodFormatterBuilder()
      .printZeroNever()
      .appendDays()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
      .appendSeparator(", ")
      .appendHours()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_HOUR), i18n.getString(TIMEUNIT_HOURS))
      .appendSeparator(", ")
      .appendMinutes()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_MINUTE), i18n.getString(TIMEUNIT_MINUTES));

  if (period.toStandardHours().getHours() == 0) {
    // Do not append seconds if the period is larger than one hour
    builder.appendSeparator(", ")
        .appendSeconds()
        .appendSuffix(" ")
        .appendSuffix(i18n.getString(TIMEUNIT_SECOND), i18n.getString(TIMEUNIT_SECONDS));
  }

  return builder.toFormatter().print(period);
}
项目:Biliomi    文件:TimeFormatter.java   
/**
 * Internal method to convert a period of greater than month scales
 *
 * @param period The period to format
 * @return A relative time string describing the period
 */
private String timeStringLargeScale(Period period) {
  return new PeriodFormatterBuilder()
      .printZeroNever()
      .appendYears()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_YEAR), i18n.getString(TIMEUNIT_YEARS))
      .appendSeparator(", ")
      .appendMonths()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_MONTH), i18n.getString(TIMEUNIT_MONTHS))
      .appendSeparator(", ")
      .appendDays()
      .appendSuffix(" ")
      .appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
      .toFormatter()
      .print(period);
}
项目:science-journal    文件:TimestampPickerController.java   
@VisibleForTesting
public TimestampPickerController(Locale locale, boolean isStartCrop, String negativePrefix,
        String hourMinuteDivider, String minuteSecondDivider,
        OnTimestampErrorListener errorListener) {
    mLocale = locale;
    mIsStartCrop = isStartCrop;
    mErrorListener = errorListener;
    mNegativePrefix = negativePrefix;
    // Builds the formatter, which will be used to read and write timestamp strings.
    mPeriodFormatter = new PeriodFormatterBuilder()
            .rejectSignedValues(true)  // Applies to all fields
            .printZeroAlways()  // Applies to all fields
            .appendHours()
            .appendLiteral(hourMinuteDivider)
            .minimumPrintedDigits(2)  // Applies to minutes and seconds
            .appendMinutes()
            .appendLiteral(minuteSecondDivider)
            .appendSecondsWithMillis()
            .toFormatter()
            .withLocale(mLocale);
}
项目:drftpd3    文件:TvMazeUtils.java   
private static String calculateAge(DateTime epDate) {

        Period period;
        if (epDate.isBefore(new DateTime())) {
            period = new Period(epDate, new DateTime());
        } else {
            period = new Period(new DateTime(), epDate);
        }

        PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendYears().appendSuffix("y")
                .appendMonths().appendSuffix("m")
                .appendWeeks().appendSuffix("w")
                .appendDays().appendSuffix("d ")
                .appendHours().appendSuffix("h")
                .appendMinutes().appendSuffix("m")
                .printZeroNever().toFormatter();

        return formatter.print(period);
    }
项目:bootstraped-multi-test-results-report    文件:Helpers.java   
private Helper<Long> dateHelper() {
    return new Helper<Long>() {
        public CharSequence apply(Long arg0, Options arg1) throws IOException {
            PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" d : ")
                .appendHours()
                .appendSuffix(" h : ")
                .appendMinutes()
                .appendSuffix(" m : ")
                .appendSeconds()
                .appendSuffix(" s : ")
                .appendMillis()
                .appendSuffix(" ms")
                .toFormatter();
            return formatter.print(new Period((arg0 * 1) / 1000000));
        }
    };
}
项目:bither-desktop-java    文件:VanitygenPanel.java   
public VanitygenPanel() {
    super(MessageKey.vanity_address, AwesomeIcon.VIMEO_SQUARE);
    passwordGetter = new PasswordPanel.PasswordGetter(VanitygenPanel.this);
    remainingTimeFormatter = new PeriodFormatterBuilder().printZeroNever().appendYears().appendSuffix
            (LocaliserUtils.getString("vanity_time_year_suffix")).appendMonths().appendSuffix
            (LocaliserUtils.getString("vanity_time_month_suffix")).appendDays().appendSuffix
            (LocaliserUtils.getString("vanity_time_day_suffix")).appendHours().appendSuffix
            (LocaliserUtils.getString("vanity_time_hour_suffix")).appendMinutes()
            .appendSuffix(LocaliserUtils.getString("vanity_time_minute_suffix"))
            .appendSeconds().appendSuffix(LocaliserUtils.getString
                    ("vanity_time_second_suffix")).toFormatter();
    setOkAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isInCalculatingView) {
                generateAddress();
            } else {
                showCalculate();
            }
        }
    });
    if (OSUtils.isWindows() && SystemUtil.isSystem32()) {
        ecKeyType = BitherSetting.ECKeyType.UNCompressed;
    }
}
项目:birudo    文件:AppUtil.java   
public static String formattedDuration(long duration) {

        PeriodFormatter hoursMinutes = new PeriodFormatterBuilder()
                .appendHours()
                .appendSuffix(" hr", " hrs")
                .appendSeparator(" ")
                .appendMinutes()
                .appendSuffix(" min", " mins")
                .appendSeparator(" ")
                .appendSeconds()
                .appendSuffix(" sec", " secs")
                .toFormatter();
        Period p = new Period(duration);

        return hoursMinutes.print(p);
    }
项目:drftpd3    文件:TvMazeUtils.java   
private static String calculateAge(DateTime epDate) {

        Period period;
        if (epDate.isBefore(new DateTime())) {
            period = new Period(epDate, new DateTime());
        } else {
            period = new Period(new DateTime(), epDate);
        }

        PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendYears().appendSuffix("y")
                .appendMonths().appendSuffix("m")
                .appendWeeks().appendSuffix("w")
                .appendDays().appendSuffix("d ")
                .appendHours().appendSuffix("h")
                .appendMinutes().appendSuffix("m")
                .printZeroNever().toFormatter();

        return formatter.print(period);
    }
项目:hadoop-mini-clusters    文件:LocalGatewayConfig.java   
public long getGatewayDeploymentsBackupAgeLimit() {
    PeriodFormatter f = (new PeriodFormatterBuilder()).appendDays().toFormatter();
    String s = this.get("gateway.deployment.backup.ageLimit", "-1");

    long d;
    try {
        Period e = Period.parse(s, f);
        d = e.toStandardDuration().getMillis();
        if (d < 0L) {
            d = -1L;
        }
    } catch (Exception var6) {
        d = -1L;
    }

    return d;
}
项目:motech    文件:JodaFormatter.java   
/**
 * Default constructor.
 */
public JodaFormatter() {

    PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder().appendYears().appendSuffix(" year", " years")
        .appendMonths().appendSuffix(" month", " months")
        .appendWeeks().appendSuffix(" week", " weeks")
        .appendDays().appendSuffix(" day", " days")
        .appendHours().appendSuffix(" hour", " hours")
        .appendMinutes().appendSuffix(" minute", " minutes")
        .appendSeconds().appendSuffix(" second", " seconds");

    periodParser = periodFormatterBuilder.toParser();
    periodFormatter = periodFormatterBuilder.toFormatter();

    dateTimeFormatter = ISODateTimeFormat.dateTime();
}
项目:togg    文件:DateTimeFormatter.java   
public static String periodHourMinBased(long secDuration) {
    PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
    PeriodFormatter formatter = null;
    String minutesAbbr = ToggApp.getApplication().getString(
            R.string.minutes_abbr);
    ;
    String hoursAbbr = ToggApp.getApplication().getString(
            R.string.hours_abbr);
    ;

    formatter = builder.printZeroAlways().minimumPrintedDigits(1)
            .appendHours().appendLiteral(" " + hoursAbbr + " ")
            .minimumPrintedDigits(2).appendMinutes()
            .appendLiteral(" " + minutesAbbr).toFormatter();

    Period period = new Period(secDuration * 1000);

    return formatter.print(period.normalizedStandard());
}
项目:societies    文件:SocietiesModule.java   
@Singleton
@Provides
public PeriodFormatter providePeriodFormatter(Dictionary<String> dictionary) {
    return new PeriodFormatterBuilder()
            .appendYears()
            .appendSuffix(" " + dictionary.getTranslation("year"), " " + dictionary.getTranslation("years"))
            .appendSeparator(" ")
            .appendMonths()
            .appendSuffix(" " + dictionary.getTranslation("month"), " " + dictionary.getTranslation("months"))
            .appendSeparator(" ")
            .appendDays()
            .appendSuffix(" " + dictionary.getTranslation("day"), " " + dictionary.getTranslation("days"))
            .appendSeparator(" ")
            .appendMinutes()
            .appendSuffix(" " + dictionary.getTranslation("minute"), " " + dictionary.getTranslation("minutes"))
            .appendSeparator(" ")
            .appendSeconds()
            .appendSuffix(" " + dictionary.getTranslation("second"), " " + dictionary.getTranslation("seconds"))
            .toFormatter();
}
项目:TCSlackNotifierPlugin    文件:SlackServerAdapter.java   
private void postFailureBuild(SRunningBuild build )
{
    String message = "";

    PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
            .printZeroRarelyFirst()
            .appendHours()
            .appendSuffix(" hour", " hours")
            .appendSeparator(" ")
            .printZeroRarelyLast()
            .appendMinutes()
            .appendSuffix(" minute", " minutes")
            .appendSeparator(" and ")
            .appendSeconds()
            .appendSuffix(" second", " seconds")
            .toFormatter();

    Duration buildDuration = new Duration(1000*build.getDuration());

    message = String.format("Project '%s' build failed! ( %s )" , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));

    postToSlack(build, message, false);
}
项目:TCSlackNotifierPlugin    文件:SlackServerAdapter.java   
private void processSuccessfulBuild(SRunningBuild build) {

        String message = "";

        PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
                    .printZeroRarelyFirst()
                    .appendHours()
                    .appendSuffix(" hour", " hours")
                    .appendSeparator(" ")
                    .printZeroRarelyLast()
                    .appendMinutes()
                    .appendSuffix(" minute", " minutes")
                    .appendSeparator(" and ")
                    .appendSeconds()
                    .appendSuffix(" second", " seconds")
                    .toFormatter();

        Duration buildDuration = new Duration(1000*build.getDuration());

        message = String.format("Project '%s' built successfully in %s." , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));

        postToSlack(build, message, true);
    }
项目:incubator-gobblin    文件:RecompactionConditionTest.java   
@Test
public void testRecompactionConditionBasedOnDuration() {
  RecompactionConditionFactory factory = new RecompactionConditionBasedOnDuration.Factory();
  RecompactionCondition conditionBasedOnDuration = factory.createRecompactionCondition(dataset);
  DatasetHelper helper = mock (DatasetHelper.class);
  when(helper.getDataset()).thenReturn(dataset);
  PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours()
      .appendSuffix("h").appendMinutes().appendSuffix("min").toFormatter();
  DateTime currentTime = getCurrentTime();

  Period period_A = periodFormatter.parsePeriod("11h59min");
  DateTime earliest_A = currentTime.minus(period_A);
  when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_A));
  when(helper.getCurrentTime()).thenReturn(currentTime);
  Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), false);

  Period period_B = periodFormatter.parsePeriod("12h01min");
  DateTime earliest_B = currentTime.minus(period_B);
  when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_B));
  when(helper.getCurrentTime()).thenReturn(currentTime);
  Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), true);
}
项目:bither-desktop-java    文件:VanitygenPanel.java   
public VanitygenPanel() {
    super(MessageKey.vanity_address, AwesomeIcon.VIMEO_SQUARE);
    passwordGetter = new PasswordPanel.PasswordGetter(VanitygenPanel.this);
    remainingTimeFormatter = new PeriodFormatterBuilder().printZeroNever().appendYears().appendSuffix
            (LocaliserUtils.getString("vanity_time_year_suffix")).appendMonths().appendSuffix
            (LocaliserUtils.getString("vanity_time_month_suffix")).appendDays().appendSuffix
            (LocaliserUtils.getString("vanity_time_day_suffix")).appendHours().appendSuffix
            (LocaliserUtils.getString("vanity_time_hour_suffix")).appendMinutes()
            .appendSuffix(LocaliserUtils.getString("vanity_time_minute_suffix"))
            .appendSeconds().appendSuffix(LocaliserUtils.getString
                    ("vanity_time_second_suffix")).toFormatter();
    setOkAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isInCalculatingView) {
                generateAddress();
            } else {
                showCalculate();
            }
        }
    });
    if (OSUtils.isWindows() && SystemUtil.isSystem32()) {
        ecKeyType = BitherSetting.ECKeyType.UNCompressed;
    }
}
项目:exportlibrary    文件:JodaTimeTests.java   
@Test
public void testDurations() {
    DateTime start = org.joda.time.DateTime.now(DateTimeZone.UTC);
    long timeout = 1000;
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }
    DateTime finish = org.joda.time.DateTime.now(DateTimeZone.UTC);
    Interval interval = new Interval(start, finish);
    Period toPeriod = interval.toPeriod();
    PeriodFormatter daysHoursMinutes = new PeriodFormatterBuilder()
            .appendDays()
            .appendSuffix(" day", " days")
            .appendSeparator(" and ")
            .appendMinutes()
            .appendSuffix(" minute", " minutes")
            .appendSeparator(" and ")
            .appendSeconds()
            .appendSuffix(" second", " seconds")
            .toFormatter();

    logger.info("[{}]", daysHoursMinutes.print(toPeriod));
}
项目:molgenis    文件:ProgressImpl.java   
@Override
public void success()
{
    jobExecution.setEndDate(Instant.now());
    jobExecution.setStatus(SUCCESS);
    jobExecution.setProgressInt(jobExecution.getProgressMax());
    Duration yourDuration = Duration.millis(timeRunning());
    Period period = yourDuration.toPeriod();
    PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendDays()
                                                                  .appendSuffix("d ")
                                                                  .appendHours()
                                                                  .appendSuffix("h ")
                                                                  .appendMinutes()
                                                                  .appendSuffix("m ")
                                                                  .appendSeconds()
                                                                  .appendSuffix("s ")
                                                                  .appendMillis()
                                                                  .appendSuffix("ms ")
                                                                  .toFormatter();
    String timeSpent = periodFormatter.print(period);
    JOB_EXECUTION_LOG.info("Execution successful. Time spent: {}", timeSpent);
    sendEmail(jobExecution.getSuccessEmail(), jobExecution.getType() + " job succeeded.", jobExecution.getLog());
    update();
    JobExecutionContext.unset();
}
项目:fenixedu-commons    文件:StyledExcelSpreadsheet.java   
public void addDuration(Duration value, int columnNumber) {
    HSSFRow currentRow = getRow();
    HSSFCell cell = currentRow.createCell(columnNumber);
    PeriodFormatter fmt =
            new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSeparator(":").minimumPrintedDigits(2)
                    .appendMinutes().toFormatter();
    MutablePeriod valueFormatted = new MutablePeriod(value.getMillis(), PeriodType.time());
    if (value.toPeriod().getMinutes() < 0) {
        valueFormatted.setMinutes(-value.toPeriod().getMinutes());
        if (value.toPeriod().getHours() == 0) {
            fmt =
                    new PeriodFormatterBuilder().printZeroAlways().appendLiteral("-").appendHours().appendSeparator(":")
                            .minimumPrintedDigits(2).appendMinutes().toFormatter();
        }
    }
    cell.setCellValue(fmt.print(valueFormatted));
    cell.setCellStyle(getExcelStyle(excelStyle.getValueStyle(), wrapText));

}
项目:crawlrss    文件:RssSite.java   
public void setMinWaitInterval(String minWaitInterval) {
    if (intervalFormatter==null) {
         intervalFormatter = new PeriodFormatterBuilder()
            .appendDays().appendSuffix("d")
            .appendHours().appendSuffix("h")
            .appendMinutes().appendSuffix("m")
            .appendSeconds().appendSuffix("s")
            .toFormatter();
    }
    this.minWaitPeriod = intervalFormatter.parsePeriod(minWaitInterval);
    // Calculate this as ms for efficiency
    minWaitPeriodMs = 
            minWaitPeriod.getDays() * MILLIS_PER_DAY +
            minWaitPeriod.getHours() * MILLIS_PER_HOUR +
            minWaitPeriod.getMinutes() * MILLIS_PER_MINUTE +
            minWaitPeriod.getSeconds() * MILLIS_PER_SECOND;
}
项目:spring-rest-server    文件:HeaderUtil.java   
private Period getSessionMaxAge() {
    String maxAge = environment.getRequiredProperty("auth.session.maxAge");
    PeriodFormatter format = new PeriodFormatterBuilder()
            .appendDays()
            .appendSuffix("d", "d")
            .printZeroRarelyFirst()
            .appendHours()
            .appendSuffix("h", "h")
            .printZeroRarelyFirst()
            .appendMinutes()
            .appendSuffix("m", "m")
            .toFormatter();
    Period sessionMaxAge = format.parsePeriod(maxAge);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Session maxAge is: "+
                formatIfNotZero(sessionMaxAge.getDays(), "days", "day") +
                formatIfNotZero(sessionMaxAge.getHours(), "hours", "hour") +
                formatIfNotZero(sessionMaxAge.getMinutes(), "minutes", "minute")
        );
    }
    return sessionMaxAge;
}
项目:amberdb    文件:DurationUtils.java   
/**
 * Converts the duration in the format of HH:MM:SS:ss to HH:MM:SS
 * @param periodHHMMSSmm
 * @return
 */
public static String convertDuration(final String periodHHMMSSmm){
    String newDuration = periodHHMMSSmm;
    PeriodFormatter hoursMinutesSecondsMilli = new PeriodFormatterBuilder()
        .appendHours()
        .appendSeparator(":")
        .appendMinutes()
        .appendSeparator(":")
        .appendSeconds()
        .appendSeparator(":")
        .appendMillis()
        .toFormatter();
    try{
        if (StringUtils.isNotBlank(periodHHMMSSmm)){
            Period period = hoursMinutesSecondsMilli.parsePeriod(periodHHMMSSmm);
            newDuration = String.format("%02d:%02d:%02d", period.getHours(), period.getMinutes(), period.getSeconds());
        }
    }catch(IllegalArgumentException e){
        log.error("Invalid duration format: " + periodHHMMSSmm);
    }
    return newDuration;
}
项目:GameResourceBot    文件:PrintUtils.java   
public static String getDiffFormatted(Date from, Date to) {
    Duration duration = new Duration(to.getTime() - from.getTime()); // in
                                                                     // milliseconds
    PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroNever()//
            .appendWeeks().appendSuffix("w").appendSeparator(" ")//
            .appendDays().appendSuffix("d").appendSeparator(" ")//
            .appendHours().appendSuffix("h").appendSeparator(" ")//
            .appendMinutes().appendSuffix("m").appendSeparator(" ")//
            .appendSeconds().appendSuffix("s")//
            .toFormatter();
    String fullTimeAgo = formatter.print(duration.toPeriod(PeriodType.yearMonthDayTime()));
    return Arrays.stream(fullTimeAgo.split(" ")).limit(2).collect(Collectors.joining(" "));
}
项目:hyperrail-for-android    文件:DurationFormatter.java   
/**
 * Format a duration (in seconds) as hh:mm
 *
 * @param duration The duration in seconds
 * @return The duration formatted as hh:mm string
 */
@SuppressLint("DefaultLocale")
public static String formatDuration(Period duration) {
    // to minutes
    PeriodFormatter hhmm = new PeriodFormatterBuilder()
            .printZeroAlways()
            .minimumPrintedDigits(2) // gives the '01'
            .appendHours()
            .appendSeparator(":")
            .appendMinutes()
            .toFormatter();
    return duration.toString(hhmm);
}
项目:memory-game    文件:ConvertUtil.java   
public static String convertMillisecondToMinutesAndSecond(long milliseconds) {
    Duration duration = new Duration(milliseconds);
    Period period = duration.toPeriod();
    PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder()
            .printZeroAlways()
            .appendMinutes()
            .appendSeparator(":")
            .appendSeconds()
            .toFormatter();
    return minutesAndSeconds.print(period);
}
项目:DiscordBot    文件:DiscordUtil.java   
public static String getTimestamp(long duration) {
    PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
            .appendYears().appendSuffix("y ")
            .appendMonths().appendSuffix("m ")
            .appendWeeks().appendSuffix("w ")
            .appendDays().appendSuffix("d ")
            .appendHours().appendSuffix("h ")
            .appendMinutes().appendSuffix("m ")
            .appendSeconds().appendSuffix("s")
            .toFormatter();
    return periodFormatter.print(new Period(new Duration(duration)).normalizedStandard());
}
项目:Cook-E    文件:TimerFragment.java   
public TimerFragment() {
    // Required empty public constructor

    mFormatter = new PeriodFormatterBuilder()
            .printZeroAlways()
            .minimumPrintedDigits(1)
            .appendHours()
            .appendLiteral(":")
            .minimumPrintedDigits(2)
            .appendMinutes()
            .appendLiteral(":")
            .appendSeconds()
            .toFormatter();
}
项目:xstreamer    文件:StartPauseButtonListener.java   
@Override
public void run() {
    Duration duration = new Duration(Activator.getCountDownTime());
    if (duration.getMillis() <= 0) {
        countDownTimer.cancel();
        return;
    }

    duration = duration.minus(1000);
    Activator.setCountDownTime(duration.getMillis());

    final Period periodLeft = duration.toPeriod();
    PeriodFormatter formatter = new PeriodFormatterBuilder().minimumPrintedDigits(2).printZeroAlways().appendHours()
            .appendSeparator(":").minimumPrintedDigits(2).printZeroAlways().appendMinutes().appendSeparator(":")
            .minimumPrintedDigits(2).printZeroAlways().appendSeconds().toFormatter();
    String formattedTime = periodLeft.toString(formatter);
    Runnable updateUi = () -> {
        int hours = periodLeft.getHours();
        int mins = periodLeft.getMinutes();
        int seconds = periodLeft.getSeconds();
        NumberFormat numberFormat = new DecimalFormat("00");
        CountDownTimerPage.hourCountDownLabel.setText(numberFormat.format(hours));
        CountDownTimerPage.minuteCountDownLabel.setText(numberFormat.format(mins));
        CountDownTimerPage.secondsCountDownLabel.setText(numberFormat.format(seconds));
    };

    Display.getDefault().asyncExec(updateUi);

    Job countDownJob = new CountDownJob("countdown", formattedTime);
    countDownJob.schedule();
}
项目:SAX    文件:SAXProcessor.java   
/**
 * Generic method to convert the milliseconds into the elapsed time string.
 * 
 * @param start Start timestamp.
 * @param finish End timestamp.
 * @return String representation of the elapsed time.
 */
public static String timeToString(long start, long finish) {

  Duration duration = new Duration(finish - start); // in milliseconds
  PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d")
      .appendHours().appendSuffix("h").appendMinutes().appendSuffix("m").appendSeconds()
      .appendSuffix("s").appendMillis().appendSuffix("ms").toFormatter();

  return formatter.print(duration.toPeriod());

}
项目:FriendCaster    文件:FeedRecyclerAdapter.java   
private String getFormattedDuration(int seconds) {
    Period period = new Period(Seconds.seconds(seconds));

    PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
            .printZeroAlways()
            .minimumPrintedDigits(2)
            .appendHours()
            .appendSeparator(":")
            .appendMinutes()
            .appendSeparator(":")
            .appendSeconds()
            .toFormatter();

    return periodFormatter.print(period.normalizedStandard());
}
项目:eMonocot    文件:Functions.java   
/**
 *
 * @param start
 *            Set the start date
 * @param end
 *            Set the end date
 * @return a formatted period
 */
public static String formatPeriod(Date start, Date end) {
 DateTime startDate = new DateTime(start);
 DateTime endDate = new DateTime(end);

 Period period = new Interval(startDate, endDate).toPeriod();
 PeriodFormatter formatter = new PeriodFormatterBuilder()
 .minimumPrintedDigits(2).appendHours().appendSeparator(":")
 .appendMinutes().appendSeparator(":").appendSeconds()
 .toFormatter();
 return formatter.print(period);
}
项目:eMonocot    文件:NotifyingJobStatusListener.java   
public NotifyingJobStatusListener() {
    ResourceBundle b = ResourceBundle.getBundle(BUNDLE_NAME, Locale.ENGLISH);
    String[] variants = {
            b.getString("PeriodFormat.space"), b.getString("PeriodFormat.comma"),
            b.getString("PeriodFormat.commandand"), b.getString("PeriodFormat.commaspaceand")};
    this.periodFormatter = new PeriodFormatterBuilder()
    .appendYears()
    .appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendMonths()
    .appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendWeeks()
    .appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendDays()
    .appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendHours()
    .appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendMinutes()
    .appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes"))
    .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants)
    .appendSeconds()
    .appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds"))
    .toFormatter();
}
项目:EncDecZip    文件:EncDecZip.java   
private String calcTimeLaps(long msLeft) {
    Period period = new Period(msLeft);
    PeriodFormatter daysHoursMinutes = new PeriodFormatterBuilder()
                                            .appendYears()
                                            .appendSuffix(" year", " years")
                                            .appendSeparator(", ")
                                            .appendMonths()
                                            .appendSuffix(" month", " months")
                                            .appendSeparator(", ")
                                            .appendWeeks()
                                            .appendSuffix(" week", " weeks")
                                            .appendSeparator(", ")
                                            .appendDays()
                                            .appendSuffix(" day", " days")
                                            .appendSeparator(" and ")
                                            .appendHours()
                                            .appendSuffix(" hour", " hours")
                                            .appendSeparator(", ")
                                            .appendMinutes()
                                            .appendSuffix(" minute", " minutes")
                                            .appendSeparator(", ")
                                            .appendSeconds()
                                            .appendSuffix(" second", " seconds")
                                            .appendSeparator(", ")
                                            .appendMillis()
                                            .appendSuffix(" millisecond", " milliseconds")
                                            .toFormatter();
    String ret = daysHoursMinutes.print(period.normalizedStandard());        
    return ret;
}
项目:sdh-vocabulary    文件:VocabularyTest.java   
@Before
public void setUp() {
    this.formatter =
        new PeriodFormatterBuilder().
            appendYears().
            appendSuffix(" year", " years").
            appendSeparator(" and ").
            printZeroRarelyLast().
            appendMonths().
            appendSuffix(" month", " months").
            appendSeparator(" and ").
            printZeroRarelyLast().
            appendDays().
            appendSuffix(" day", " days").
            appendSeparator(" and ").
            printZeroRarelyLast().
            appendHours().
            appendSuffix(" hour", " hours").
            appendSeparator(" and ").
            printZeroRarelyLast().
            appendMinutes().
            appendSuffix(" minute", " minutes").
            appendSeparator(" and ").
            printZeroRarelyLast().
            toFormatter();
    FunctionRegistry.get().put("http://example.org/function#yearMonth", YearMonthFunction.class) ;
}
项目:TLMReaderLib    文件:FlightDefinition.java   
@Override
public String toString() {
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours().appendSuffix(":").appendMinutes()
            .appendSuffix(":").appendSeconds().appendSuffix(".").appendMillis().toFormatter();

    return this.modelName + " duration: " + formatter.print(this.getDuration().toPeriod());
}
项目:TLMReaderLib    文件:Flight.java   
@Override
public String toString() {
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours().appendSuffix(":").appendMinutes()
            .appendSuffix(":").appendSeconds().appendSuffix(".").appendMillis().toFormatter();

    return this.modelName + " duration: " + formatter.print(this.getDuration().toPeriod());
}
项目:TLMReaderLib    文件:App.java   
private static String duration(Duration flightDuration) {
    Period period = flightDuration.toPeriod();
    PeriodFormatter hms = new PeriodFormatterBuilder().appendHours().appendSeparator(":").printZeroAlways()
            .appendMinutes().appendSeparator(":").appendSecondsWithMillis().toFormatter();

    return hms.print(period);
}
项目:jspresso-ce    文件:DurationFormatter.java   
/**
 * Constructs a new {@code DurationFormatter} instance.
 *
 * @param translationProvider
 *          the translation provider for duration labels.
 * @param locale
 *          the locale the formatter must be constructed in.
 */
public DurationFormatter(ITranslationProvider translationProvider,
    Locale locale, boolean secondsAware, boolean millisecondsAware) {
  super();
  PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
  builder.appendDays();
  builder.appendSuffix(
      " " + translationProvider.getTranslation("day", locale), " "
          + translationProvider.getTranslation("days", locale));
  builder.appendSeparator(" ");
  builder.appendHours();
  builder.appendSuffix(
      " " + translationProvider.getTranslation("hour", locale), " "
          + translationProvider.getTranslation("hours", locale));
  builder.appendSeparator(" ");
  builder.appendMinutes();
  builder.appendSuffix(
      " " + translationProvider.getTranslation("minute", locale), " "
          + translationProvider.getTranslation("minutes", locale));
  if (secondsAware) {
    builder.appendSeconds();
    builder.appendSuffix(" " + translationProvider.getTranslation("second", locale),
        " " + translationProvider.getTranslation("seconds", locale));
  }
  if (millisecondsAware) {
    builder.appendMillis();
    builder.appendSuffix(" " + translationProvider.getTranslation("millisecond", locale),
        " " + translationProvider.getTranslation("milliseconds", locale));
  }
  this.formatter = builder.toFormatter().withLocale(locale);
}