]> source.dussan.org Git - sonarqube.git/commitdiff
HOURS_IN_DAY property should not be read in the constructor
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 19 Feb 2014 13:54:30 +0000 (14:54 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 19 Feb 2014 13:54:30 +0000 (14:54 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java

index 30e2e6c8187dc76b4543ff8669e7704080718c09..6ed686036dcfba691db917b26f38db64fcd939c3 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 
 import javax.annotation.Nullable;
+
 import java.io.Serializable;
 
 /**
@@ -98,9 +99,9 @@ public class WorkDuration implements Serializable {
 
   static WorkDuration createFromSeconds(long seconds, int hoursInDay) {
     int days = (int) (seconds / hoursInDay / 60d / 60d);
-    long currentDurationInSeconds = seconds - (days * hoursInDay * 60 * 60);
+    long currentDurationInSeconds = seconds - (days * hoursInDay * 3600);
     int hours = (int) (currentDurationInSeconds / 60d / 60d);
-    currentDurationInSeconds = currentDurationInSeconds - (hours * 60 * 60);
+    currentDurationInSeconds = currentDurationInSeconds - (hours * 3600);
     int minutes = (int) (currentDurationInSeconds / 60d);
     return new WorkDuration(seconds, days, hours, minutes, hoursInDay);
   }
index 9e84017fe90aed90927dd7eb191cd71c3b4d734c..7ecf0d83ba3d5f4b0a399f229f945391d5faa8ef 100644 (file)
@@ -30,18 +30,22 @@ import org.sonar.api.config.Settings;
  */
 public final class WorkDurationFactory implements BatchComponent, ServerComponent {
 
-  private final int hoursInDay;
+  private final Settings settings;
 
   public WorkDurationFactory(Settings settings) {
-    this.hoursInDay = settings.getInt(CoreProperties.HOURS_IN_DAY);
+    this.settings = settings;
   }
 
   public WorkDuration createFromWorkingValue(int value, WorkDuration.UNIT unit) {
-    return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay);
+    return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay());
   }
 
   public WorkDuration createFromWorkingLong(long duration) {
-    return WorkDuration.createFromLong(duration, hoursInDay);
+    return WorkDuration.createFromLong(duration, hoursInDay());
+  }
+
+  private int hoursInDay(){
+    return settings.getInt(CoreProperties.HOURS_IN_DAY);
   }
 
 }