fix DateUtil.endOfYear

This commit is contained in:
Looly
2019-09-15 14:32:00 +08:00
parent aa12a8e408
commit f26fad33cb
9 changed files with 117 additions and 92 deletions

View File

@@ -7,7 +7,6 @@ import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
/**
* 类型转换工具单元测试
@@ -28,7 +27,7 @@ public class ConvertTest {
int a = 1;
long[] b = { 1, 2, 3, 4, 5 };
Console.log(Convert.convert(String.class, b));
Assert.assertEquals("[1, 2, 3, 4, 5]", Convert.convert(String.class, b));
String aStr = Convert.toStr(a);
Assert.assertEquals("1", aStr);

View File

@@ -56,6 +56,16 @@ public class DateModifierTest {
begin = DateUtil.truncate(date, DateField.YEAR);
Assert.assertEquals("2017-01-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
@Test
public void truncateDayOfWeekInMonthTest() {
String dateStr = "2017-03-01 22:33:23.123";
Date date = DateUtil.parse(dateStr);
// 天day of xxx按照day处理
DateTime begin = DateUtil.truncate(date, DateField.DAY_OF_WEEK_IN_MONTH);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
@Test
public void ceilingTest() {

View File

@@ -477,12 +477,23 @@ public class DateUtilTest {
Assert.assertEquals("2019-05-16 17:57:18", time.toString());
}
@Test
public void endOfYearTest() {
DateTime date = DateUtil.date();
date.setField(DateField.YEAR, 2019);
DateTime endOfYear = DateUtil.endOfYear(date);
Assert.assertEquals("2019-12-31 23:59:59", endOfYear.toString());
}
@Test
public void endOfWeekTest() {
DateTime now = DateUtil.date();
// 周日
DateTime now = DateUtil.parse("2019-09-15 13:00");
DateTime startOfWeek = DateUtil.beginOfWeek(now);
Assert.assertEquals("2019-09-09 00:00:00", startOfWeek.toString());
DateTime endOfWeek = DateUtil.endOfWeek(now);
Assert.assertEquals("2019-09-15 23:59:59", endOfWeek.toString());
long between = DateUtil.between(endOfWeek, startOfWeek, DateUnit.DAY);
// 周一和周日相距6天

View File

@@ -1,13 +0,0 @@
package cn.hutool.core.io;
import org.junit.Test;
import cn.hutool.core.lang.Console;
public class IoUtilTest {
@Test
public void moveTest() {
Console.log(2 << 14);
}
}