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 @@ -607,14 +607,16 @@ public static Expression unixTimestamp(StringLikeLiteral date, StringLikeLiteral
private static String getTimestamp(LocalDateTime dateTime) {
LocalDateTime specialUpperBound = LocalDateTime.of(2038, 1, 19, 3, 14, 7);
LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 0);
dateTime = dateTime.atZone(DateUtils.getTimeZone())
.toOffsetDateTime().atZoneSameInstant(ZoneId.of("UTC+0"))
.toLocalDateTime();
if (dateTime.isBefore(specialLowerBound) || dateTime.isAfter(specialUpperBound)) {
return "0";
}
Duration duration = Duration.between(
specialLowerBound,
dateTime.atZone(DateUtils.getTimeZone())
.toOffsetDateTime().atZoneSameInstant(ZoneId.of("UTC+0"))
.toLocalDateTime());
dateTime
);
if (duration.getNano() == 0) {
return String.valueOf(duration.getSeconds());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ suite("fold_constant_date_arithmatic") {
testFoldConst("select next_day('2020-02-29', 'MON');") // 2020-03-02 (leap year to next month)
testFoldConst("select next_day('2019-02-26', 'THU');") // 2019-02-28 (non-leap year)
testFoldConst("select next_day('2019-02-28', 'SUN');") // 2019-03-03 (non-leap year to next month)

// test unix_timestamp
testFoldConst("select unix_timestamp('2023/04/31');")
testFoldConst("select unix_timestamp('1970/01/01 00:00:00');")
testFoldConst("select unix_timestamp('1970-01-01T00:00:00');")
testFoldConst("select unix_timestamp('1970-01-01');")
testFoldConst("select unix_timestamp('31/Apr/2023','%d/%b/%Y');")
testFoldConst("select unix_timestamp('00-00-0000');")
testFoldConst("select unix_timestamp('3000/02/29','%Y/%m/%d');")
testFoldConst("select unix_timestamp('01.Jan.1970','%d.%b.%Y');")
testFoldConst("select unix_timestamp('0000-00-00 00:00:00');")
testFoldConst("select unix_timestamp();")
testFoldConst("select unix_timestamp('2021-02-29', '%Y-%m-%d');")
testFoldConst("select unix_timestamp('2023/04/31', '%Y/%m/%d');")
testFoldConst("select unix_timestamp('2023-04-31 12:00:00');")
testFoldConst("select unix_timestamp('1970-01-01','%Y-%m-%d');")
testFoldConst("select unix_timestamp('0');")
}