Duration totalDuration = Duration.ZERO;  Attributes overlappedAttributes = findAttributesIntervalThatOverlapFromAttributes(normalWorkPeriodAttribute, DomainConstants.WORKED_ATTRIBUTES);  for (AttributeType attribute: overlappedAttributes.getAttributes()) { TimeInterval attributeInterval = findIntervalByAttribute(attribute); totalDuration = totalDuration.plus(attributeInterval.getDuration()); } return totalDuration;
Duration totalDuration = Duration.ZERO;  Attributes overlappedAttributes = findAttributesIntervalThatOverlapFromAttributes( normalWorkPeriodAttribute, DomainConstants.WORKED_ATTRIBUTES);  for (AttributeType attribute : overlappedAttributes.getAttributes()) { TimePoint[] attributeInterval = findIntervalByAttribute(attribute); DateTime startDate = attributeInterval[0].getTime().toDateTimeToday(); DateTime endDate = attributeInterval[1].getTime().toDateTimeToday(); if (attributeInterval[0].isNextDay() != attributeInterval[1].isNextDay()) { endDate = endDate.plusDays(1); } totalDuration = totalDuration.plus(new Duration(startDate, endDate)); } return totalDuration;
    public Duration calculateNormalWorkPeriod(AttributeType normalWorkPeriodAttribute) {    		Duration totalDuration = Duration.ZERO;    		// get the workedAttributes during the normal work period    		Attributes overlappedAttributes = findAttributesIntervalThatOverlapFromAttributes(normalWorkPeriodAttribute, DomainConstants.WORKED_ATTRIBUTES);    		// since the worked times are not overlapped lets calculate each duration    		for (AttributeType attribute: overlappedAttributes.getAttributes()) {    			TimeInterval attributeInterval = findIntervalByAttribute(attribute);    			totalDuration = totalDuration.plus(attributeInterval.getDuration());    		}    		return totalDuration;    }