Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.

Commit be4fe1d

Browse files
committed
fix: time of today and this month
1 parent 0d9d036 commit be4fe1d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main/java/org/code4everything/boot/base/DateUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private DateUtils() {}
4242
* @since 1.1.3
4343
*/
4444
public static Date getStartOfThisMonth() {
45-
return checkThisMonth(startOfThisMonth, startOfThisMonthCopier);
45+
return checkThisMonth(true, startOfThisMonthCopier);
4646
}
4747

4848
/**
@@ -53,7 +53,7 @@ public static Date getStartOfThisMonth() {
5353
* @since 1.1.3
5454
*/
5555
public static Date getEndOfThisMonth() {
56-
return checkThisMonth(endOfThisMonth, endOfThisMonthCopier);
56+
return checkThisMonth(false, endOfThisMonthCopier);
5757
}
5858

5959
/**
@@ -64,7 +64,7 @@ public static Date getEndOfThisMonth() {
6464
* @since 1.0.9
6565
*/
6666
public static Date getStartOfToday() {
67-
return checkToday(startOfToday, startOfTodayCopier);
67+
return checkToday(true, startOfTodayCopier);
6868
}
6969

7070
/**
@@ -75,35 +75,35 @@ public static Date getStartOfToday() {
7575
* @since 1.0.9
7676
*/
7777
public static Date getEndOfToday() {
78-
return checkToday(endOfToday, endOfTodayCopier);
78+
return checkToday(false, endOfTodayCopier);
7979
}
8080

8181
/**
8282
* 使用副本来防止原引用被篡改
8383
*/
84-
private static Date checkThisMonth(long origin, Date copier) {
84+
private static Date checkThisMonth(boolean isStart, Date copier) {
8585
long curr = System.currentTimeMillis();
8686
if (curr > endOfThisMonth) {
8787
// 如果当前的时间戳超过了endOfThisMonth的时间戳,说明ThisMonth的时间戳已经过期,需重新设置
8888
Date date = new Date();
8989
startOfThisMonth = DateUtil.beginOfMonth(date).getTime();
9090
endOfThisMonth = DateUtil.endOfMonth(date).getTime();
9191
}
92-
return check(origin, copier);
92+
return check(isStart ? startOfThisMonth : endOfThisMonth, copier);
9393
}
9494

9595
/**
9696
* 使用副本来防止原引用被篡改
9797
*/
98-
private static Date checkToday(long origin, Date copier) {
98+
private static Date checkToday(boolean isStart, Date copier) {
9999
long curr = System.currentTimeMillis();
100100
if (curr > endOfToday) {
101101
// 如果当前的时间戳超过了endOfToday的时间戳,说明Today的时间戳已经过期,需重新设置
102102
Date date = new Date();
103103
startOfToday = DateUtil.beginOfDay(date).getTime();
104104
endOfToday = DateUtil.endOfDay(date).getTime();
105105
}
106-
return check(origin, copier);
106+
return check(isStart ? startOfToday : endOfToday, copier);
107107
}
108108

109109
private static Date check(long origin, Date copier) {

0 commit comments

Comments
 (0)