mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package org.dromara.hutool.core.date.format.parser;
|
||||
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GlobalRegexDateParserTest {
|
||||
|
||||
@Test
|
||||
void parseMonthFirstTest() {
|
||||
assertParse("2009-05-08 05:57:51", "May 8, 2009 5:57:51");
|
||||
assertParse("2009-05-08 17:57:51", "May 8, 2009 5:57:51 PM");
|
||||
assertParse("2009-05-08 17:57:51", "May 8, 2009 5:57:51 pm");
|
||||
assertParse("2009-05-08 17:57:51", "May 8, 2009 5:57:51pm");
|
||||
assertParse("2009-05-08 05:57:51", "May 8, 2009 5:57:51 +08:00");
|
||||
assertParse("2009-05-08 05:57:51", "May 8, 2009 5:57:51 +0800");
|
||||
assertParse("2009-05-08 05:57:51", "May 8, 2009 5:57:51 +08");
|
||||
assertParse("2009-05-08 00:00:00", "May 8, 2009");
|
||||
assertParse("2009-05-08 00:00:00", "May 8th, 2009");
|
||||
assertParse("2009-05-08 00:00:00", "May 8th, 09");
|
||||
assertParse("2009-05-08 00:00:00", "may. 8th, 09");
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseWeekFirstTest() {
|
||||
assertParse("2006-01-02 15:04:05", "Mon Jan 2, 2006 15:04:05");
|
||||
assertParse("2006-01-02 15:04:05", "Mon Jan 2 2006 15:04:05");
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseWeekFirstYearLastTest() {
|
||||
assertParse("2006-01-02 15:04:05", "Mon Jan 2 15:04:05 2006");
|
||||
assertParse("2006-01-02 15:04:05", "Mon Jan 2 15:04:05 MST 2006");
|
||||
assertParse("2006-01-03 06:04:05", "Mon Jan 02 15:04:05 -0700 2006");
|
||||
//assertParse("2006-01-03 06:04:05", "Monday, 02-Jan-06 15:04:05 MST");
|
||||
}
|
||||
|
||||
private static void assertParse(final String dateStr, final String dateStrToParse) {
|
||||
final Date date = GlobalRegexDateParser.parse(dateStrToParse);
|
||||
assertEquals(dateStr, DateUtil.date(date).toString());
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package org.dromara.hutool.core.date.format.parser;
|
||||
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.dromara.hutool.core.date.Week;
|
||||
import org.dromara.hutool.core.regex.ReUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -59,6 +60,15 @@ public class RegexDateParserTest {
|
||||
assertMatch(zoneNameRegex, " (GMT Daylight Time)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void weekMatchTest() {
|
||||
final String weekRegex = "(?<week>[mwfts][oeruha][ndieut](\\w{3,6})?)";
|
||||
for (final Week week : Week.values()) {
|
||||
assertMatch(weekRegex, week.name());
|
||||
assertMatch(weekRegex, week.name().substring(0, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsePureTest() {
|
||||
// yyyyMMdd
|
||||
|
Reference in New Issue
Block a user