Java Code Examples for org.apache.commons.lang3.time.DurationFormatUtils#formatDuration()

The following examples show how to use org.apache.commons.lang3.time.DurationFormatUtils#formatDuration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReportController.java    From jlineup with Apache License 2.0 6 votes vote down vote up
private static String getDurationAsString(JLineupRunStatus status) {

        final AtomicLong durationMillis = new AtomicLong();
        Instant startTime = status.getStartTime();

        status.getPauseTime().ifPresent(pauseTime -> durationMillis.addAndGet(Duration.between(startTime, pauseTime).toMillis()));
        status.getEndTime().ifPresent(endTime -> durationMillis.addAndGet(Duration.between(status.getResumeTime().orElse(endTime), endTime).toMillis()));

        if (status.getState() == State.BEFORE_RUNNING) {
           durationMillis.addAndGet(Duration.between(startTime, Instant.now()).toMillis());
        } else if (status.getState() == State.AFTER_RUNNING) {
            durationMillis.addAndGet(Duration.between(status.getResumeTime().orElse(Instant.now()), Instant.now()).toMillis());
        }

        return DurationFormatUtils.formatDuration(durationMillis.get(), "HH:mm:ss");
    }
 
Example 2
Source File: CommonUtils.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
public static String formatDuration(long millis) {
    if (millis < 0) {
        millis = 0;
    }
    String format = "mm:ss";
    if (millis > 3600000) {
        format = "HH:mm:ss";
    }
    return DurationFormatUtils.formatDuration(millis, format);
}
 
Example 3
Source File: ProximityForestResult.java    From ProximityForest with GNU General Public License v3.0 5 votes vote down vote up
public void printResults(String datasetName, int experiment_id, String prefix) {
		
//		System.out.println(prefix+ "-----------------Experiment No: " 
//				+ experiment_id + " (" +datasetName+ "), Forest No: " 
//				+ (this.forest_id) +"  -----------------");
		
		if (AppContext.verbosity > 0) {
			String time_duration = DurationFormatUtils.formatDuration((long) (elapsedTimeTrain/1e6), "H:m:s.SSS");
	        System.out.format("%sTraining Time: %fms (%s)\n",prefix, elapsedTimeTrain/1e6, time_duration);
			time_duration = DurationFormatUtils.formatDuration((long) (elapsedTimeTest/1e6), "H:m:s.SSS");		
	        System.out.format("%sPrediction Time: %fms (%s)\n",prefix, elapsedTimeTest/1e6, time_duration);
	
	        
	        System.out.format("%sCorrect(TP+TN): %d vs Incorrect(FP+FN): %d\n",prefix,  correct, errors);
	        System.out.println(prefix+"Accuracy: " + accuracy);
	        System.out.println(prefix+"Error Rate: "+ error_rate);			
		}

        
        this.collateResults();
        
        //this is just the same info in a single line, used to grep from output and save to a csv, use the #: marker to find the line easily
       
        //the prefix REPEAT is added to this comma separated line easily use grep from command line to filter outputs to a csv file
        //just a quick method to filter important info while in command line
        
        String pre = "REPEAT:" + (experiment_id+1) +" ,";
		System.out.print(pre + datasetName);        
		System.out.print(", " + accuracy);
		System.out.print(", " + elapsedTimeTrain /1e6);
		System.out.print(", " + elapsedTimeTest /1e6);
		System.out.print(", " + mean_depth_per_tree);
//		System.out.print(", " + mean_weighted_depth_per_tree);
		System.out.println();
	}
 
Example 4
Source File: OpenTimeHistoricMetricProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Pongo measure(Project project) {
	BugsOpenTimeHistoricMetric avgBugOpenTime = new BugsOpenTimeHistoricMetric();
	if (uses.size() == 1) {
		BugsBugMetadataTransMetric usedBhm = ((BugMetadataTransMetricProvider)uses.get(0)).adapt(context.getProjectDB(project));
		long seconds = 0;
		int durations = 0;
		for (BugData bugData: usedBhm.getBugData()) {
			if (bugData.getLastClosedTime()!=null) {
				java.util.Date javaOpenTime = bugData.getCreationTime();
				java.util.Date javaCloseTime = bugData.getLastClosedTime();
				seconds += ( Date.duration(javaOpenTime, javaCloseTime) / 1000);
				durations++;
			}
		}
		
		if (durations>0)
		{
			long avgDuration = seconds / durations;
			double daysReal = ( (double) avgDuration ) / SECONDS_DAY;
			avgBugOpenTime.setAvgBugOpenTimeInDays(daysReal);
			int days = (int) daysReal;
			long lessThanDay = (avgDuration % SECONDS_DAY);
			String formatted = DurationFormatUtils.formatDuration(lessThanDay*1000, "HH:mm:ss:SS");
			avgBugOpenTime.setAvgBugOpenTime(days+":"+formatted);
			System.out.println(days + ":" + formatted);
			avgBugOpenTime.setBugsConsidered(durations);
		}

	}
	return avgBugOpenTime;
}
 
Example 5
Source File: FarmTableModel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    FarmInformation elem = (FarmInformation) FarmManager.getSingleton().getAllElements().get(rowIndex);
    switch (columnIndex) {
        case 0:
            return elem.getStatus();
        case 1:
            return elem.isResourcesFoundInLastReport();
        case 2:
            return new Date(elem.getLastReport());
        case 3:
            return elem.getVillage().getShortName();
        case 4:
            return elem.getSiegeStatus();
        case 5:
            return elem.getWallLevel();
        case 6:
            return elem.getStorageStatus();
        case 7:
            long t = elem.getRuntimeInformation();
            t = (t <= 0) ? 0 : t;
            if (t == 0) {
                return "Keine Truppen unterwegs";
            }
            return DurationFormatUtils.formatDuration(t, "HH:mm:ss", true);
        case 8:
            return elem.getLastResult();
        default:
            return elem.getCorrectionFactor();
    }
}
 
Example 6
Source File: StringUtil.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Formats a duration to M:SS or H:MM:SS or M:SS.mmm
 */
public static String formatDuration(long millis, boolean convertToHours) {
    String format = "m:ss";
    if (millis >= 3600000 && convertToHours) {
        format = "H:m" + format;
    }

    if (millis % 1000 != 0) {
        format = format + ".S";
    }

    return DurationFormatUtils.formatDuration(millis, format);
}
 
Example 7
Source File: ReportRule.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public String getStringRepresentation() {
    switch(type) {
    case AGE:
        return "Bericht älter als " + DurationFormatUtils
                .formatDuration((Long) filterComponent, "dd", false) + " Tag(e)";
    case ATTACKER_ALLY:
        return "Angreifende Stämme " + StringUtils.join((List<Ally>) filterComponent, ", ");
    case ATTACKER_TRIBE:
        return "Angreifer " + StringUtils.join((List<Tribe>) filterComponent, ", ");
    case CATA:
        return "Berichte mit Gebäudebeschädigung";
    case COLOR:
        StringBuilder result = new StringBuilder();
        int color = (Integer) filterComponent;
        result.append("Farben:");
        if ((color & GREY) > 0)
            result.append(" grau");
        
        if ((color & BLUE) > 0)
            result.append(" blau");

        if ((color & GREEN) > 0)
            result.append(" grün");

        if ((color & YELLOW) > 0)
            result.append(" gelb");

        if ((color & RED) > 0)
            result.append(" rot");

        return result.toString();
    case CONQUERED:
        return "AG-Angriffe/Eroberungen";
    case DATE:
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy");
        Range<Long> dates = (Range<Long>) filterComponent;
        return "Gesendet zwischen " + df.format(new Date(dates.getMinimum())) +
                " und " + df.format(new Date(dates.getMaximum()));
    case DEFENDER_ALLY:
        return "Verteidigende Stämme " + StringUtils.join((List<Ally>) filterComponent, ", ");
    case DEFENDER_TRIBE:
        return "Verteidiger " + StringUtils.join((List<Tribe>) filterComponent, ", ");
    case FAKE:
        return "Fakes";
    case FARM:
        return "Farmberichte";
    case OFF:
        return "Off-Berichte";
    case WALL:
        return "Berichte mit Wallbeschädigung";
    default:
        throw new IllegalArgumentException("wrong type");
    }
}
 
Example 8
Source File: JavaUtils.java    From Singularity with Apache License 2.0 4 votes vote down vote up
public static String durationFromMillis(final long millis) {
  return DurationFormatUtils.formatDuration(Math.max(millis, 0), DURATION_FORMAT);
}
 
Example 9
Source File: Classifier.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
private String time(long timeInMS) {
	return DurationFormatUtils.formatDuration(timeInMS, "HH:mm:ss,SSS");
}
 
Example 10
Source File: GeneralUtilities.java    From ProximityForest with GNU General Public License v3.0 4 votes vote down vote up
public static String formatTime(long duration, String format) {
	return DurationFormatUtils.formatDuration((long) duration, "H:m:s.SSS");
}
 
Example 11
Source File: JavaUtils.java    From Singularity with Apache License 2.0 4 votes vote down vote up
public static String duration(final long start) {
  return DurationFormatUtils.formatDuration(
    Math.max(System.currentTimeMillis() - start, 0),
    DURATION_FORMAT
  );
}
 
Example 12
Source File: BigButtonBean.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
public String formatDuration(Date from, Date to) {

		if (to == null || from == null) {
			return "";
		}

		return DurationFormatUtils.formatDuration(to.getTime() - from.getTime(), "HH:mm:ss");

	}
 
Example 13
Source File: DateFormatUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * 单位为毫秒,必须大于0,可大于1天
 */
public static String formatDurationOnSecond(long durationMillis) {
	return DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss");
}
 
Example 14
Source File: DateFormatUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * 单位为毫秒,必须大于0,可大于1天
 * 
 * @see DurationFormatUtils
 */
public static String formatDurationOnSecond(long durationMillis) {
	return DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss");
}
 
Example 15
Source File: DateFormatUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * endDate必须大于startDate,间隔可大于1天
 * 
 * @see DurationFormatUtils
 */
public static String formatDurationOnSecond(@NotNull Date startDate, @NotNull Date endDate) {
	return DurationFormatUtils.formatDuration(endDate.getTime() - startDate.getTime(), "HH:mm:ss");
}
 
Example 16
Source File: DateFormatTools.java    From pampas with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * <p>
 * 单位为毫秒,必须大于0,可大于1天
 *
 * @param durationMillis the duration millis
 * @return the string
 */
public static String formatDurationOnSecond(long durationMillis) {
    return DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss");
}
 
Example 17
Source File: DateFormatTools.java    From pampas with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * <p>
 * endDate必须大于startDate,间隔可大于1天
 *
 * @param startDate the start date
 * @param endDate   the end date
 * @return the string
 */
public static String formatDurationOnSecond(Date startDate, Date endDate) {
    return DurationFormatUtils.formatDuration(endDate.getTime() - startDate.getTime(), "HH:mm:ss");
}
 
Example 18
Source File: DateFormatUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * 单位为毫秒,必须大于0,可大于1天
 * 
 * @see DurationFormatUtils
 */
public static String formatDurationOnSecond(long durationMillis) {
	return DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss");
}
 
Example 19
Source File: DateFormatUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * endDate必须大于startDate,间隔可大于1天
 * 
 * @see DurationFormatUtils
 */
public static String formatDurationOnSecond(@NotNull Date startDate, @NotNull Date endDate) {
	return DurationFormatUtils.formatDuration(endDate.getTime() - startDate.getTime(), "HH:mm:ss");
}
 
Example 20
Source File: DateFormatUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 按HH:mm:ss格式,格式化时间间隔
 * 
 * endDate必须大于startDate,间隔可大于1天
 */
public static String formatDurationOnSecond(@NotNull Date startDate, @NotNull Date endDate) {
	return DurationFormatUtils.formatDuration(endDate.getTime() - startDate.getTime(), "HH:mm:ss");
}