From 8cc87296999865ba132d70a7888679576caf2014 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 14 Oct 2022 16:58:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=B8=83=E5=A4=A9=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E4=BB=8E=E5=91=A8=E6=97=A5=E5=88=B0=E5=91=A8?= =?UTF-8?q?=E5=85=AD=E6=94=B9=E4=B8=BA=E4=BB=8E=E5=91=A8=E4=B8=80=E5=88=B0?= =?UTF-8?q?=E5=91=A8=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1017103 --user=宋天阳 【接口测试】接口测试首页场景用例数量统计本周执行次数不正确 {#_orginal_url#} --- .../metersphere/commons/utils/DateUtils.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java index 645ed0908f..d1bad332c3 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java @@ -77,25 +77,18 @@ public class DateUtils { public static Map getWeedFirstTimeAndLastTime(Date date) { Map returnMap = new HashMap<>(); Calendar calendar = Calendar.getInstance(); - - //Calendar默认一周的开始是周日。业务需求从周一开始算,所以要"+1" - int weekDayAdd = 1; - + calendar.setFirstDayOfWeek(Calendar.MONDAY); try { - calendar.setTime(date); - calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK)); - calendar.add(Calendar.DAY_OF_MONTH, weekDayAdd); - + int dayWeek = calendar.get(Calendar.DAY_OF_WEEK); + if (dayWeek == 1) { + dayWeek = 8; + } + calendar.add(Calendar.DATE, calendar.getFirstDayOfWeek() - dayWeek); //第一天的时分秒是 00:00:00 这里直接取日期,默认就是零点零分 Date thisWeekFirstTime = getDate(getDateString(calendar.getTime())); - calendar.clear(); - calendar.setTime(date); - calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMaximum(Calendar.DAY_OF_WEEK)); - calendar.add(Calendar.DAY_OF_MONTH, weekDayAdd); - - //最后一天的时分秒应当是23:59:59。 处理方式是增加一天计算日期再-1 - calendar.add(Calendar.DAY_OF_MONTH, 1); + //计算七天过后的日期 + calendar.add(Calendar.DATE, 7); Date nextWeekFirstDay = getDate(getDateString(calendar.getTime())); Date thisWeekLastTime = getTime(getTimeString(nextWeekFirstDay.getTime() - 1));