- Timestamp:
- 2014-01-10T16:39:29+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6652 r6661 833 833 * Returns a simple human readable (hours, minutes, seconds) string for a given duration in milliseconds. 834 834 * @param elapsedTime The duration in milliseconds 835 * @return A human re dable string for the given duration835 * @return A human readable string for the given duration 836 836 * @throws IllegalArgumentException if elapsedTime is < 0 837 837 * @since 6354 838 838 */ 839 839 public static String getDurationString(long elapsedTime) throws IllegalArgumentException { 840 final int MILLIS_OF_SECOND = 1000; 841 final int MILLIS_OF_MINUTE = 60000; 842 final int MILLIS_OF_HOUR = 3600000; 843 final int MILLIS_OF_DAY = 86400000; 840 844 if (elapsedTime < 0) { 841 845 throw new IllegalArgumentException("elapsedTime must be > 0"); 842 846 } 843 847 // Is it less than 1 second ? 844 if (elapsedTime < 1000) {848 if (elapsedTime < MILLIS_OF_SECOND) { 845 849 return String.format("%d %s", elapsedTime, tr("ms")); 846 850 } 847 851 // Is it less than 1 minute ? 848 if (elapsedTime < 60*1000) {849 return String.format("%.1f %s", elapsedTime /1000f, tr("s"));852 if (elapsedTime < MILLIS_OF_MINUTE) { 853 return String.format("%.1f %s", elapsedTime / (float) MILLIS_OF_SECOND, tr("s")); 850 854 } 851 855 // Is it less than 1 hour ? 852 if (elapsedTime < 60*60*1000) { 853 return String.format("%d %s %d %s", elapsedTime/60000, tr("min"), elapsedTime/1000, tr("s")); 856 if (elapsedTime < MILLIS_OF_HOUR) { 857 final long min = elapsedTime / MILLIS_OF_MINUTE; 858 return String.format("%d %s %d %s", min, tr("min"), (elapsedTime - min * MILLIS_OF_MINUTE) / MILLIS_OF_SECOND, tr("s")); 854 859 } 855 860 // Is it less than 1 day ? 856 if (elapsedTime < 24*60*60*1000) { 857 return String.format("%d %s %d %s", elapsedTime/3600000, tr("h"), elapsedTime/60000, tr("min")); 858 } 859 long days = elapsedTime/86400000; 860 return String.format("%d %s %d %s", days, trn("day", "days", days), elapsedTime/3600000, tr("h")); 861 if (elapsedTime < MILLIS_OF_DAY) { 862 final long hour = elapsedTime / MILLIS_OF_HOUR; 863 return String.format("%d %s %d %s", hour, tr("h"), (elapsedTime - hour * MILLIS_OF_HOUR) / MILLIS_OF_MINUTE, tr("min")); 864 } 865 long days = elapsedTime / MILLIS_OF_DAY; 866 return String.format("%d %s %d %s", days, trn("day", "days", days), (elapsedTime - days * MILLIS_OF_DAY) / MILLIS_OF_HOUR, tr("h")); 861 867 } 862 868
Note:
See TracChangeset
for help on using the changeset viewer.