Commit 6864d60d authored by yanzg's avatar yanzg

表结构修改

parent 74abb526
...@@ -5,8 +5,10 @@ import com.yanzuoguang.util.exception.ExceptionHelper; ...@@ -5,8 +5,10 @@ import com.yanzuoguang.util.exception.ExceptionHelper;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
...@@ -1053,4 +1055,59 @@ public class DateHelper { ...@@ -1053,4 +1055,59 @@ public class DateHelper {
return (Math.abs(month + result) + surplus); return (Math.abs(month + result) + surplus);
} }
/**
* 获取小时中的刻度时间
*
* @param day 拆分起止日期
* @return 拆分信息
*/
public static List<Day> splitDayTime(Day day) {
Date fromDate = getDateTime(day.getFrom());
Date toDate = getDateTime(day.getTo());
Date dayStart = fromDate;
List<Day> ret = new ArrayList<>();
while (dayStart.getTime() <= toDate.getTime()) {
String from = DateHelper.getDateTimeString(dayStart);
Date dayEnd = DateHelper.getDayEnd(dayStart);
long minEnd = Math.min(toDate.getTime(), dayEnd.getTime());
String to = DateHelper.getDateTimeString(new Date(minEnd));
ret.add(new Day(from, to));
dayStart = DateHelper.getDayStart(DateHelper.addDay(dayStart, 1));
}
return ret;
}
/**
* 每日日期拆分
*/
public static class Day {
private String from;
private String to;
public Day() {
}
public Day(String from, String to) {
this.from = from;
this.to = to;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
}
} }
package helper; package helper;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.thread.ThreadHelper; import com.yanzuoguang.util.thread.ThreadHelper;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.text.ParseException; import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.List;
public class TestDateHelper { public class TestDateHelper {
...@@ -47,4 +50,12 @@ public class TestDateHelper { ...@@ -47,4 +50,12 @@ public class TestDateHelper {
Date date = DateHelper.getDateTime("00:00:00"); Date date = DateHelper.getDateTime("00:00:00");
System.out.println("日期转换时间是否相等:" + (date != null)); System.out.println("日期转换时间是否相等:" + (date != null));
} }
@Test
public void testSplitDay() {
List<DateHelper.Day> days = DateHelper.splitDayTime(new DateHelper.Day("2023-7-1 10:00:00", "2023-7-31 19:00:00"));
String json = JsonHelper.serialize(days);
System.out.println(json);
Assert.assertEquals("[{\"from\":\"2023-07-01 10:00:00\",\"to\":\"2023-07-01 23:59:59\"},{\"from\":\"2023-07-02 00:00:00\",\"to\":\"2023-07-02 23:59:59\"},{\"from\":\"2023-07-03 00:00:00\",\"to\":\"2023-07-03 23:59:59\"},{\"from\":\"2023-07-04 00:00:00\",\"to\":\"2023-07-04 23:59:59\"},{\"from\":\"2023-07-05 00:00:00\",\"to\":\"2023-07-05 23:59:59\"},{\"from\":\"2023-07-06 00:00:00\",\"to\":\"2023-07-06 23:59:59\"},{\"from\":\"2023-07-07 00:00:00\",\"to\":\"2023-07-07 23:59:59\"},{\"from\":\"2023-07-08 00:00:00\",\"to\":\"2023-07-08 23:59:59\"},{\"from\":\"2023-07-09 00:00:00\",\"to\":\"2023-07-09 23:59:59\"},{\"from\":\"2023-07-10 00:00:00\",\"to\":\"2023-07-10 23:59:59\"},{\"from\":\"2023-07-11 00:00:00\",\"to\":\"2023-07-11 23:59:59\"},{\"from\":\"2023-07-12 00:00:00\",\"to\":\"2023-07-12 23:59:59\"},{\"from\":\"2023-07-13 00:00:00\",\"to\":\"2023-07-13 23:59:59\"},{\"from\":\"2023-07-14 00:00:00\",\"to\":\"2023-07-14 23:59:59\"},{\"from\":\"2023-07-15 00:00:00\",\"to\":\"2023-07-15 23:59:59\"},{\"from\":\"2023-07-16 00:00:00\",\"to\":\"2023-07-16 23:59:59\"},{\"from\":\"2023-07-17 00:00:00\",\"to\":\"2023-07-17 23:59:59\"},{\"from\":\"2023-07-18 00:00:00\",\"to\":\"2023-07-18 23:59:59\"},{\"from\":\"2023-07-19 00:00:00\",\"to\":\"2023-07-19 23:59:59\"},{\"from\":\"2023-07-20 00:00:00\",\"to\":\"2023-07-20 23:59:59\"},{\"from\":\"2023-07-21 00:00:00\",\"to\":\"2023-07-21 23:59:59\"},{\"from\":\"2023-07-22 00:00:00\",\"to\":\"2023-07-22 23:59:59\"},{\"from\":\"2023-07-23 00:00:00\",\"to\":\"2023-07-23 23:59:59\"},{\"from\":\"2023-07-24 00:00:00\",\"to\":\"2023-07-24 23:59:59\"},{\"from\":\"2023-07-25 00:00:00\",\"to\":\"2023-07-25 23:59:59\"},{\"from\":\"2023-07-26 00:00:00\",\"to\":\"2023-07-26 23:59:59\"},{\"from\":\"2023-07-27 00:00:00\",\"to\":\"2023-07-27 23:59:59\"},{\"from\":\"2023-07-28 00:00:00\",\"to\":\"2023-07-28 23:59:59\"},{\"from\":\"2023-07-29 00:00:00\",\"to\":\"2023-07-29 23:59:59\"},{\"from\":\"2023-07-30 00:00:00\",\"to\":\"2023-07-30 23:59:59\"},{\"from\":\"2023-07-31 00:00:00\",\"to\":\"2023-07-31 19:00:00\"}]", json);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment