154 lines
5.0 KiB
Java
154 lines
5.0 KiB
Java
package com.engine.bjcj220907.utils;
|
||
|
||
import com.engine.salary.util.SalaryDateUtil;
|
||
|
||
import java.text.SimpleDateFormat;
|
||
import java.time.LocalDate;
|
||
import java.util.Calendar;
|
||
import java.util.Date;
|
||
|
||
/**
|
||
* @author Harryxzy
|
||
* @date 2022/09/26 13:55
|
||
* @description
|
||
*/
|
||
public class BjcjCommonUtils {
|
||
|
||
/***
|
||
* @description 获取当前calendar
|
||
* @return Calendar
|
||
* @author Harryxzy
|
||
* @date 2022/9/26 14:44
|
||
*/
|
||
public static Calendar getNowCalendar(){
|
||
Date date = new Date();
|
||
Calendar cal = Calendar.getInstance();
|
||
cal.setTime(date);
|
||
return cal;
|
||
}
|
||
|
||
/***
|
||
* @description 根据考勤所属月获取考勤开始日期
|
||
* @return Calendar
|
||
* @author Harryxzy
|
||
* @date 2022/9/14 21:57
|
||
*/
|
||
public static Calendar getStartAttendanceCal(Date bonusMonth){
|
||
Calendar startAttendanceCal = Calendar.getInstance();
|
||
startAttendanceCal.setTime(bonusMonth);
|
||
startAttendanceCal.add(Calendar.MONTH,-1);
|
||
if(startAttendanceCal.getActualMaximum(Calendar.DAY_OF_MONTH) == 28){
|
||
// 2月只有28天的情况(从3.1开始)
|
||
startAttendanceCal.add(Calendar.MONTH, 1);
|
||
startAttendanceCal.set(Calendar.DAY_OF_MONTH, 1);
|
||
startAttendanceCal.set(Calendar.HOUR_OF_DAY, 0);
|
||
startAttendanceCal.set(Calendar.MINUTE, 0);
|
||
startAttendanceCal.set(Calendar.SECOND, 0);
|
||
startAttendanceCal.set(Calendar.MILLISECOND, 0);
|
||
}else{
|
||
startAttendanceCal.set(Calendar.DAY_OF_MONTH, 29);
|
||
startAttendanceCal.set(Calendar.HOUR_OF_DAY, 0);
|
||
startAttendanceCal.set(Calendar.MINUTE, 0);
|
||
startAttendanceCal.set(Calendar.SECOND, 0);
|
||
startAttendanceCal.set(Calendar.MILLISECOND, 0);
|
||
}
|
||
return startAttendanceCal;
|
||
}
|
||
|
||
|
||
/***
|
||
* @description 根据考勤所属月获取考勤结束日期
|
||
* @return Calendar
|
||
* @author Harryxzy
|
||
* @date 2022/9/14 21:57
|
||
*/
|
||
public static Calendar getEndAttendanceCal(Date bonusMonth){
|
||
Calendar endAttendanceCal = Calendar.getInstance();
|
||
endAttendanceCal.setTime(bonusMonth);
|
||
endAttendanceCal.set(Calendar.DAY_OF_MONTH,28);
|
||
endAttendanceCal.set(Calendar.HOUR_OF_DAY, 23);
|
||
endAttendanceCal.set(Calendar.MINUTE, 59);
|
||
endAttendanceCal.set(Calendar.SECOND, 59);
|
||
endAttendanceCal.set(Calendar.MILLISECOND, 999);
|
||
return endAttendanceCal;
|
||
}
|
||
|
||
|
||
/**
|
||
* @description 获取2个时间段中有多少天
|
||
* @return Long
|
||
* @author Harryxzy
|
||
* @date 2022/9/11 20:12
|
||
*/
|
||
public static int getDays(Date startDate,Date endDate) {
|
||
int days = (int)( (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24) + 1);
|
||
return days;
|
||
}
|
||
|
||
/**
|
||
* @description 判断某一天是否在某一个时间区间内
|
||
* @return Long
|
||
* @author Harryxzy
|
||
* @date 2022/9/11 20:12
|
||
*/
|
||
public static boolean isBetween(Date now,Date startDate,Date endDate) {
|
||
if( (now.after(startDate) || now.equals(startDate)) && ( (now.before(endDate) || now.equals(endDate)) )){
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public static boolean isBeforeMonth(Date a,Date b){
|
||
|
||
try {
|
||
if(a == null || b == null){
|
||
return false;
|
||
}
|
||
// 如果入离职的日期>28 则属于下一个月
|
||
LocalDate bLocalDate = SalaryDateUtil.dateToLocalDate(b);
|
||
if(bLocalDate.getDayOfMonth() > 28){
|
||
LocalDate localDate = bLocalDate.plusMonths(1);
|
||
b = SalaryDateUtil.localDateToDate(localDate);
|
||
}
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
||
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
|
||
Date formatA = sdf.parse(sdf2.format(a));
|
||
Date formatB = sdf.parse(sdf2.format(b));
|
||
if( formatA.before(formatB) ){
|
||
return true;
|
||
}
|
||
return false;
|
||
}catch (Exception e){
|
||
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public static boolean isEqualsMonth(Date a,Date kqMonth){
|
||
|
||
try {
|
||
if(a == null || kqMonth == null){
|
||
return false;
|
||
}
|
||
// 如果入离职的日期>28 则属于下一个月
|
||
LocalDate aLocalDate = SalaryDateUtil.dateToLocalDate(a);
|
||
if(aLocalDate.getDayOfMonth() > 28){
|
||
LocalDate localDate = aLocalDate.plusMonths(1);
|
||
a = SalaryDateUtil.localDateToDate(localDate);
|
||
}
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
||
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
|
||
Date formatA = sdf.parse(sdf2.format(a));
|
||
Date formatB = sdf.parse(sdf2.format(kqMonth));
|
||
if( formatA.equals(formatB) ){
|
||
return true;
|
||
}
|
||
return false;
|
||
}catch (Exception e){
|
||
|
||
}
|
||
return false;
|
||
}
|
||
|
||
}
|