weaver-hrm-salary/src/demo.java

72 lines
2.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
public class demo {
public static void main(String[] args) {
//全天会议可用的时间点900-1800每15min。
List<LocalTime> allTime = new ArrayList() {{
//初始化全天可用的时间点集合可以仿照下面splitTimeRange()写个。
add(LocalTime.of(9, 0));
add(LocalTime.of(9, 15));
add(LocalTime.of(9, 30));
add(LocalTime.of(9, 45));
add(LocalTime.of(10, 0));
//.....
add(LocalTime.of(17, 45));
add(LocalTime.of(18, 0));
}};
//占用的时间点,(从数据库里查的)
List<String> takeUpStringList = new ArrayList(){{
}};
List<LocalTime> takeUpTimeList = takeUpStringList.stream().map(LocalTime::parse).collect(Collectors.toList());
//比较两个时间点数组,将全天的时间点分割
List<Integer> indexList = new ArrayList<>();
for (int i = 0; i < allTime.size(); i++) {
//比较
for (int j = 0; j < takeUpTimeList.size(); j++) {
if (allTime.get(i).equals(takeUpTimeList.get(j))) {
indexList.add(i);
}
}
}
//按indexList下标分割allTime获取list
List<List<LocalTime>> list = new ArrayList<>();
for (int i = 0; i < indexList.size(); i++) {
if (indexList.get(i) != 0 && (i + 1) != indexList.size()) {
list.add(allTime.subList(indexList.get(i), indexList.get(i + 1)));
} else {
list.add(allTime.subList(0, indexList.get(i)));
}
}
//获取超出1小时的时间段就是集合里时间点大于等于5的集合
//取出集合返回,接口要求可能就是返回时间-时间,取集合第一个-集合末尾
}
private static void splitTimeRange() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//设置时间格式
Date end = new Date();
Date start = new Date();
List<String> list = new ArrayList<String>();//用来接收划分后的时间
//进行循环将时间按照分钟进行划分
for (Date i = start; i.before(end); ) {
list.add(simpleDateFormat.format(i));
i.setMinutes(i.getMinutes() + 1);
}
}
}