Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ public void testIllegalDateType() {
statement.execute("CREATE DATABASE root.sg1");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s5 WITH DATATYPE=TIMESTAMP, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
try {
statement.execute("insert into root.sg1.d1(timestamp, s4) values(1, '2022-04-31')");
fail();
Expand All @@ -1205,6 +1207,18 @@ public void testIllegalDateType() {
+ "Please use YYYY-MM-DD format.]",
e.getMessage());
}
try {
statement.execute(
"insert into root.sg1.d1(timestamp, s5) values(1999-04-31T00:00:00.000+08:00, 1999-04-31T00:00:00.000+08:00)");
fail();
} catch (Exception e) {
assertEquals(
TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ ": Input time format 1999-04-31T00:00:00.000+08:00 error. "
+ "Input like yyyy-MM-dd HH:mm:ss, yyyy-MM-ddTHH:mm:ss "
+ "or refer to user document for more info.",
e.getMessage());
}
} catch (SQLException e) {
fail();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void testCreateTopic_invalidTime5()
printTopics("testCreateTopic_invalidTime5");
}

@Test
@Test(expected = StatementExecutionException.class)
public void testCreateTopic_invalidTime6()
throws IoTDBConnectionException,
StatementExecutionException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.time.format.SignStyle;
import java.time.temporal.ChronoField;
import java.util.Calendar;
Expand Down Expand Up @@ -507,7 +508,8 @@ public static long correctPrecision(long millis) {

/** such as '2011.12.03 10:15:30+01:00' or '2011.12.03 10:15:30.123456789+01:00'. */
.appendOptional(ISO_OFFSET_DATE_TIME_WITH_DOT_WITH_SPACE_NS)
.toFormatter();
.toFormatter()
.withResolverStyle(ResolverStyle.STRICT);

public static long convertTimestampOrDatetimeStrToLongWithDefaultZone(String timeStr) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class DateTimeUtilsTest {

Expand Down Expand Up @@ -78,6 +79,19 @@ public void convertDatetimeStrToLongTest3() {
testConvertDateStrToLong(zoneOffset, zoneId, timestamp1 + delta);
}

@Test
public void convertDatetimeStrToLongTest4() {
zoneOffset = ZoneOffset.UTC;
try {
DateTimeUtils.convertDatetimeStrToLong("1999-02-29T00:00:00.000", zoneOffset, 0, "ms");
fail();
} catch (Exception e) {
assertEquals(
"Text '1999-02-29T00:00:00.000+00:00' could not be parsed: Invalid date 'February 29' as '1999' is not a leap year",
e.getMessage());
}
}

/** Test time precision is ms. */
@Test
public void convertDurationStrToLongTest1() {
Expand Down