import org.apache.commons.lang.builder.ToStringStyle;
import javax.annotation.Nullable;
+
import java.io.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);
}
*/
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);
}
}