View Javadoc

1   package net.sourceforge.jpotpourri.util;
2   
3   /**
4    * @author christoph_pickl@users.sourceforge.net
5    */
6   public final class Duration {
7       
8   	private final int minutes;
9       private final int hours;
10      private final int totalInMinutes;
11      
12      private Duration(final int minutes, final int hours) {
13          this.minutes = minutes;
14          this.hours = hours;
15          this.totalInMinutes = calcTotalMinutes(minutes, hours);
16      }
17      
18      public int getHours() {
19          return this.hours;
20      }
21      
22      public int getMinutes() {
23          return this.minutes;
24      }
25      
26      public int getTotalInMinutes() {
27          return this.totalInMinutes;
28      }
29      
30      public String formatStringShort() {
31          return DurationUtil.formatDurationShort(this);
32      }
33      
34      private static int calcTotalMinutes(final int minutes, final int hours) {
35          return hours * 60 + minutes;
36      }
37      
38      public static Duration newByTotal(final int totalMinutes) {
39          final int minutes = totalMinutes % 60;
40          final int hours = (int) Math.ceil(totalMinutes / 60);
41          return new Duration(minutes, hours);
42      }
43      
44      public static Duration newByMinHour(final int minutes, final int hours) {
45          return new Duration(minutes, hours);
46      }
47  }