Skip to content
Open
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 @@ -349,15 +349,22 @@
+ milli;
}

/**
* Whether the string is a non-negative decimal integer that fits in an {@code int}. Callers
* hand the string straight to {@link Integer#parseInt}, so the range matters as much as the
* characters.
*/
private static boolean isInteger(String s) {
boolean isInt = s.length() > 0;
if (s.isEmpty() || s.length() > 10) {
return false;
}
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) < '0' || s.charAt(i) > '9') {
isInt = false;
break;
return false;
}
}
return isInt;
// ten digits still reach past Integer.MAX_VALUE
return s.length() < 10 || Long.parseLong(s) <= Integer.MAX_VALUE;
}

private static boolean isIllegalDate(int y, int m, int d) {
Expand Down Expand Up @@ -546,7 +553,7 @@

public static Timestamp parseTimestampData(String dateStr, int precision, TimeZone timeZone)
throws DateTimeException {
return Timestamp.fromInstant(

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / eslib_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.2)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (1.20)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.13)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 556 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.12)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated
fromTemporalAccessor(DEFAULT_TIMESTAMP_FORMATTER.parse(dateStr), precision)
.atZone(timeZone.toZoneId())
.toInstant());
Expand Down Expand Up @@ -625,11 +632,11 @@
// --------------------------------------------------------------------------------------------

public static Timestamp timestampToTimestampWithLocalZone(Timestamp ts, TimeZone tz) {
return Timestamp.fromInstant(ts.toLocalDateTime().atZone(tz.toZoneId()).toInstant());

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / eslib_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.2)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (1.20)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.13)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 635 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.12)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated
}

public static Timestamp timestampWithLocalZoneToTimestamp(Timestamp ts, TimeZone tz) {
return Timestamp.fromLocalDateTime(LocalDateTime.ofInstant(ts.toInstant(), tz.toZoneId()));

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / eslib_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.2)

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (1.20)

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.13)

toInstant() in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 639 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.12)

toInstant() in org.apache.paimon.data.Timestamp has been deprecated
}

public static int timestampWithLocalZoneToDate(Timestamp ts, TimeZone tz) {
Expand All @@ -645,7 +652,7 @@
}

public static Timestamp dateToTimestampWithLocalZone(int date, TimeZone tz) {
return Timestamp.fromInstant(

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / eslib_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.2)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (1.20)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.13)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated

Check warning on line 655 in paimon-common/src/main/java/org/apache/paimon/utils/DateTimeUtils.java

View workflow job for this annotation

GitHub Actions / build_test (2.12)

fromInstant(java.time.Instant) in org.apache.paimon.data.Timestamp has been deprecated
LocalDateTime.of(toLocalDate(date), LocalTime.MIDNIGHT)
.atZone(tz.toZoneId())
.toInstant());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
/** Test for {@link DateTimeUtils}. */
public class DateTimeUtilsTest {

@Test
public void testParseDateAndTimeOverflowReturnsNull() {
// A component too large for an int is an invalid date or time, not a crash: the
// contract of parseDate/parseTime is null for unparseable input. 2147483648 is
// Integer.MAX_VALUE + 1, the smallest ten-digit value that does not fit.
assertThat(DateTimeUtils.parseDate("2147483648-01-01")).isNull();
assertThat(DateTimeUtils.parseDate("2147483647-01-01"))
.isNull(); // in range, but not a year
assertThat(DateTimeUtils.parseDate("99999999999-01-01")).isNull();
assertThat(DateTimeUtils.parseDate("2024-99999999999-01")).isNull();
assertThat(DateTimeUtils.parseDate("2024-01-99999999999")).isNull();
assertThat(DateTimeUtils.parseTime("99999999999:00:00")).isNull();

// Sanity: valid values still parse.
assertThat(DateTimeUtils.parseDate("2024-01-15")).isNotNull();
assertThat(DateTimeUtils.parseTime("12:30:00")).isNotNull();
}

@Test
public void testFormatLocalDateTime() {
LocalDateTime time = LocalDateTime.of(2023, 8, 30, 12, 30, 59, 999_999_999);
Expand Down
Loading