yao-zengchun
2026-01-08 c7ed489cee1127e3b4f96edf74e24b01c065ac2a
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/domain/Calculate.java
@@ -8,6 +8,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Data
@AllArgsConstructor
@@ -77,4 +78,26 @@
        return result;
    }
    /**
     * 判断与另一个时间区间是否有交集
     */
    public Boolean overlapsWith(Calculate otherCalculate) {
        Objects.requireNonNull(otherCalculate, "另一个时间区间不能为null");
        return !this.end.isBefore(otherCalculate.start) && !otherCalculate.end.isBefore(this.start);
    }
    /**
     * 获取交集区间(没有返回null)
     */
    public Calculate getOverlap(Calculate other) {
        if (!overlapsWith(other)) {
            return null;
        }
        LocalDateTime overlapStart = this.start.isAfter(other.start) ? this.start : other.start;
        LocalDateTime overlapEnd = this.end.isBefore(other.end) ? this.end : other.end;
        return new Calculate(overlapStart, overlapEnd);
    }
}