(long seconds)
| 43 | } |
| 44 | |
| 45 | public static StringBuilder format(long seconds) { |
| 46 | StringBuilder time = new StringBuilder(); |
| 47 | long days = TimeUnit.SECONDS.toDays(seconds); |
| 48 | if (days > 0) { |
| 49 | time.append(days).append(days == 1 ? " day " : " days "); |
| 50 | seconds -= TimeUnit.DAYS.toSeconds(days); |
| 51 | } |
| 52 | long hours = TimeUnit.SECONDS.toHours(seconds); |
| 53 | if (hours > 0) { |
| 54 | time.append(hours).append(hours == 1 ? " hour " : " hours "); |
| 55 | seconds -= TimeUnit.HOURS.toSeconds(hours); |
| 56 | } |
| 57 | /* Only include minute granularity if we're < 1 day. */ |
| 58 | if (days < 1) { |
| 59 | long minutes = TimeUnit.SECONDS.toMinutes(seconds); |
| 60 | if (minutes > 0) { |
| 61 | time.append(minutes).append(minutes == 1 ? " minute " : " minutes "); |
| 62 | seconds -= TimeUnit.MINUTES.toSeconds(seconds); |
| 63 | } |
| 64 | } |
| 65 | /* Only bother to include seconds if we're < 1 minute */ |
| 66 | if (time.length() == 0) { |
| 67 | time.append(seconds).append(time.length() == 1 ? " second " : " seconds "); |
| 68 | } |
| 69 | return time; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
no outgoing calls