当前位置:网站首页>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
边栏推荐
- 如何进行应用安全测试(AST)
- Nacos 详解,有点东西
- Install MySQL on MAC
- 最詳細的背包問題!!!
- GRBL学习(二)
- Best practice of cloud migration in education industry: Haiyun Jiexun uses hypermotion cloud migration products to implement progressive migration for a university in Beijing, with a success rate of 1
- Oracle data pump usage
- About JMeter startup flash back
- Homewbrew installation, common commands and installation path
- Oak-d raspberry pie cloud project [with detailed code]
猜你喜欢

Meaning and usage of volatile

Sail soft calls the method of dynamic parameter transfer and sets parameters in the title

Gartner 发布新兴技术研究:深入洞悉元宇宙
欣旺达:HEV和BEV超快充拳头产品大规模出货

Website pressure measurement tools Apache AB, webbench, Apache jemeter

VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file

ESP32编译环境的搭建

第十天 异常机制

RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page

OAK-D树莓派点云项目【附详细代码】
随机推荐
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
Gartner announces emerging technology research: insight into the meta universe
05 Lua control structure
Day 9 static abstract class interface
Cartoon: what are IAAs, PAAS, SaaS?
Install redis and deploy redis high availability cluster
VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file
Matplotlib tutorial 05 --- operating images
Report FCRA test question set and answers (11 wrong questions)
100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)
Research and Practice on business system migration of a government cloud project
The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
Day (3) of picking up matlab
Jour (9) de ramassage de MATLAB
Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
Hypermotion cloud migration completes Alibaba cloud proprietary cloud product ecological integration certification
Homewbrew installation, common commands and installation path
homwbrew安装、常用命令以及安装路径
下载并安装MongoDB
Differences between MySQL BTREE index and hash index