[feature] 添加长安十二时辰与现代时间的互转

This commit is contained in:
VampireAchao
2024-02-25 20:59:14 +08:00
committed by VampireAchao
parent fdd5d914bb
commit 30ea0060a5
2 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package org.dromara.hutool.core.date.chinese;
import org.dromara.hutool.core.date.DateBetween;
import org.dromara.hutool.core.date.DateUnit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* ChangAnTimeConverterTest
*
* @author achao@apache.org
*/
public class ChangAnTimeConverterTest {
@Test
void testToModernTimeForAllTimes() {
// 测试每个时辰的转换
String[] times = {"", "", "", "", "", "", "", "", "", "", "", ""};
int[] expectedHours = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
for (int i = 0; i < times.length; i++) {
DateBetween dateBetween = ChangAnTimeConverter.toModernTime(times[i] + "");
long hoursBetween = dateBetween.between(DateUnit.HOUR);
Assertions.assertEquals(expectedHours[i], hoursBetween, times[i] + "时 should last for 2 hours.");
}
}
@Test
void testToChangAnTimeForAllHours() {
// 从23时开始测试因为子时开始于23时
String[] expectedTimes = {"子时", "丑时", "丑时", "寅时", "寅时", "卯时", "卯时", "辰时", "辰时", "巳时", "巳时", "午时", "午时", "未时", "未时", "申时", "申时", "酉时", "酉时", "戌时", "戌时", "亥时", "亥时", "子时"};
for (int hour = 0; hour < 24; hour++) {
String expectedTime = expectedTimes[hour];
String actualTime = ChangAnTimeConverter.toChangAnTime(hour);
Assertions.assertEquals(expectedTime, actualTime, "Hour " + hour + " should be in " + expectedTime);
}
}
}