当前位置:网站首页>Execution plan calculation for different time types
Execution plan calculation for different time types
2022-04-23 16:31:00 【Spilled off】
1. Problem description :
To be described ...
2. Code :
public class DateTimeUtil {
private static final DateTimeFormatter DAY_FULL_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
/** * Get a list of all execution times by type and start time * @param startTime Starting time * @param endTime End time * @param type type : day( God ), week( Zhou ), month( month ), quarter( quarter ), year( year ) * @return List of execution dates */
public static List<String> getExecuteDaysByType(String type, LocalDateTime startTime, LocalDateTime endTime) {
LocalDate startDate = startTime.toLocalDate(), endDate = endTime.toLocalDate();
LocalDateTime now = LocalDateTime.now();
LocalDate today = now.toLocalDate();
if("day".equalsIgnoreCase(type)){
if(startDate.isBefore(today)){
startDate = today;
}
return getExecDays(startDate, endDate, now, date -> date.plusDays(1));
}
if("week".equalsIgnoreCase(type)){
// Monday corresponding to the start time
startDate = startDate.minusDays(startDate.getDayOfWeek().getValue()-1);
// This Monday
LocalDate currMonday = today.minusDays(today.getDayOfWeek().getValue()-1);
if(startDate.isBefore(currMonday)){
startDate = currMonday;
}
return getExecDays(startDate, endDate, now, date -> date.plusDays(7));
}
if("month".equalsIgnoreCase(type)){
// The starting time is in the current month 1 Number
startDate = LocalDate.of(startDate.getYear(), startDate.getMonthValue(), 1);
// This month, 1 Number
LocalDate currMonth = LocalDate.of(today.getYear(), today.getMonthValue(), 1);
if(startDate.isBefore(currMonth)){
startDate = currMonth;
}
return getExecDays(startDate, endDate, now, date -> date.plusMonths(1));
}
if("quarter".equalsIgnoreCase(type)){
// Start in the first month of the quarter 1 Number
startDate = LocalDate.of(startDate.getYear(), startDate.getMonth().firstMonthOfQuarter(), 1);
// The first month of this quarter 1 Number
LocalDate currQuarter = LocalDate.of(today.getYear(), today.getMonth().firstMonthOfQuarter(), 1);
if(startDate.isBefore(currQuarter)){
startDate = currQuarter;
}
return getExecDays(startDate, endDate, now, date -> date.plusMonths(3));
}
if("year".equalsIgnoreCase(type)){
// Start in the first month of the year 1 Number
startDate = LocalDate.of(startDate.getYear(), 1, 1);
// First month of the year 1 Number
LocalDate currYear = LocalDate.of(today.getYear(), 1, 1);
if(startDate.isBefore(currYear)){
startDate = currYear;
}
return getExecDays(startDate, endDate, now, date -> date.plusYears(1));
}
return Collections.emptyList();
}
private static List<String> getExecDays(LocalDate startDate, LocalDate endDate, LocalDateTime now, Function<LocalDate, LocalDate> timePlus){
LocalDate today = now.toLocalDate();
List<String> execDays = new ArrayList<>();
while(!startDate.isAfter(endDate)){
if(!startDate.isAfter(today)){
// The execution time is today and before today , At the current time 5 Execute in minutes
execDays.add(now.plusMinutes(5).format(DAY_FULL_FMT));
}else{
execDays.add(startDate.atStartOfDay().format(DAY_FULL_FMT));
}
// Next execution date
startDate = timePlus.apply(startDate);
}
return execDays;
}
}
4.Test:
public static void main(String[] args) {
LocalDateTime startTime = LocalDateTime.of(2020, 7, 1, 12, 0, 0);
LocalDateTime endTime = LocalDateTime.of(2022, 6, 1, 0, 0, 0);
System.out.println(DateTimeUtil.getExecuteDaysByType("year", startTime, endTime));
}
版权声明
本文为[Spilled off]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231403163246.html
边栏推荐
- ESP32编译环境的搭建
- Sort by character occurrence frequency 451
- The most detailed knapsack problem!!!
- 文件系统读写性能测试实战
- linux上启动oracle服务
- 捡起MATLAB的第(10)天
- Day 10 abnormal mechanism
- RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
- Install redis and deploy redis high availability cluster
- Day (3) of picking up matlab
猜你喜欢
人脸识别框架之dlib
VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file
磁盘管理与文件系统
捡起MATLAB的第(5)天
力扣-746.使用最小花费爬楼梯
Countdown 1 day ~ 2022 online conference of cloud disaster tolerance products is about to begin
Postman batch production body information (realize batch modification of data)
阿里研发三面,面试官一套组合拳让我当场懵逼
Nacos 详解,有点东西
Install MySQL on MAC
随机推荐
Sail soft segmentation solution: take only one character (required field) of a string
How to quickly batch create text documents?
JIRA screenshot
安装Redis并部署Redis高可用集群
Qipengyuan horizon credible meta universe social system meets diversified consumption and social needs
浅谈 NFT项目的价值、破发、收割之争
力扣-198.打家劫舍
JSP learning 1
299. Number guessing game
Xinwangda: HEV and Bev super fast charging fist products are shipped on a large scale
Using JSON server to create server requests locally
Win11/10家庭版禁用Edge的inprivate浏览功能
捡起MATLAB的第(10)天
Day (8) of picking up matlab
homwbrew安装、常用命令以及安装路径
通过Feign在服务之间传递header请求头信息
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
七朋元视界可信元宇宙社交体系满足多元化的消费以及社交需求
LVM与磁盘配额