Skip to content

Commit

Permalink
HIVE-28337: TestMetaStoreUtils fails for invalid timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
KiranVelumuri committed Jun 18, 2024
1 parent 7f87a3b commit fbda4fc
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
Expand All @@ -50,7 +51,7 @@ public class TestMetaStoreUtils {
private final String date;
private final String timestamp;

public TestMetaStoreUtils(String zoneId, LocalDateTime timestamp) {
public TestMetaStoreUtils(String zoneId, ZonedDateTime timestamp) {
this.timezone = TimeZone.getTimeZone(zoneId);
this.timestamp = timestamp.format(FORMATTER);
this.date = timestamp.toLocalDate().format(DateTimeFormatter.ISO_LOCAL_DATE);
Expand All @@ -59,12 +60,13 @@ public TestMetaStoreUtils(String zoneId, LocalDateTime timestamp) {
@Parameterized.Parameters(name = "zoneId={0}, timestamp={1}")
public static Collection<Object[]> generateZoneTimestampPairs() {
List<Object[]> params = new ArrayList<>();
long minDate = LocalDate.of(0, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC);
long minDate = LocalDate.of(1, 1, 1).atStartOfDay().toEpochSecond(ZoneOffset.UTC);
long maxDate = LocalDate.of(9999, 12, 31).atStartOfDay().toEpochSecond(ZoneOffset.UTC);
new Random(23).longs(500, minDate, maxDate).forEach(i -> {
LocalDateTime datetime = LocalDateTime.ofEpochSecond(i, 0, ZoneOffset.UTC);
for (String zone : ZoneId.SHORT_IDS.values()) {
params.add(new Object[] { zone, datetime });
ZonedDateTime zonedDateTime = ZonedDateTime.of(datetime, ZoneId.of(zone));
params.add(new Object[] { zone, zonedDateTime });
}
});
return params;
Expand Down

0 comments on commit fbda4fc

Please sign in to comment.