Commit 4cc9f59d by 朽木不可雕也

修复未来N小时内,随机错误

parent 1747ed9b
......@@ -34,7 +34,7 @@ public class TimeUtil {
public static Date randomHour(int hour) {
long openInterval = System.currentTimeMillis();
long closeInterval = openInterval + hour * 60 * 60 * 1000L;
long randomTime = openInterval + (long) (Math.random() * (openInterval - closeInterval + 1));
long randomTime = openInterval + (long) (Math.random() * (closeInterval - openInterval + 1));
return new Date(randomTime);
}
}
......@@ -3,7 +3,9 @@ package com.zhiweidata.automatictest.barragecrawlerserver.util;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import static com.zhiweidata.automatictest.publics.BeanContainer.STANDARD_DATE_FORMAT;
import static com.zhiweidata.automatictest.barragecrawlerserver.util.TimeUtil.randomDay;
/**
* @author aszswaz
......@@ -15,8 +17,16 @@ import static com.zhiweidata.automatictest.publics.BeanContainer.STANDARD_DATE_F
class TimeUtilTest {
@Test
void randmoDate() {
Date date = TimeUtil.randomDay(7);
void randomDate() {
Date date = randomDay(7);
log.info(STANDARD_DATE_FORMAT.format(date));
}
@Test
void randomHour() {
for (int i = 0; i < 10; i++) {
Date date = TimeUtil.randomHour(5);
log.info(STANDARD_DATE_FORMAT.format(date));
}
}
}
\ No newline at end of file
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