Skip to content

[FLINK-37854][table] Support DATE_FORMAT with zone #26705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 @@ -729,7 +729,7 @@ public static String formatTimestamp(TimestampData ts, TimeZone tz, int precisio
private static String formatTimestamp(TimestampData ts, String format, ZoneId zoneId) {
DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(format);
Instant instant = ts.toInstant();
return LocalDateTime.ofInstant(instant, zoneId).format(formatter);
return instant.atZone(zoneId).format(formatter);
}

public static String formatTimestampMillis(long ts, String format, TimeZone tz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,41 @@ class CalcITCase extends BatchTestBase {
)
}

@Test
def testDateFormatWithZone(): Unit = {
// Test whether the output is correct, if typeInfo is Instant or DateTimeFormatter contains time zone information
val shanghai = ZoneId.of("Asia/Shanghai")
val ldt = localDateTime("2015-06-09 08:09:08")
val data = Seq(
row(
ldt,
ldt.toInstant(shanghai.getRules.getOffset(ldt))
)
)
registerCollection("T", data, new RowTypeInfo(LOCAL_DATE_TIME, INSTANT), "a, b")
checkResult(
"SELECT DATE_FORMAT(a, 'yy-M-d H:m:s')," +
" DATE_FORMAT(a, 'yyyy-MM-dd HH:mm:ss')," +
" DATE_FORMAT(b, 'yy-M-d H:m:s')," +
" DATE_FORMAT(b, 'yyyy-MM-dd HH:mm:ss')," +
" DATE_FORMAT(b, 'yyyy-MM-dd HH:mm:ssX')," +
" DATE_FORMAT(b, 'yyyy-MM-dd HH:mm:ssXX')," +
" DATE_FORMAT(b, 'yyyy-MM-dd HH:mm:ssXXX')" +
" FROM T",
Seq(
row(
"15-6-9 8:9:8",
"2015-06-09 08:09:08",
"15-6-9 8:9:8",
"2015-06-09 08:09:08",
"2015-06-09 08:09:08+08",
"2015-06-09 08:09:08+0800",
"2015-06-09 08:09:08+08:00"
)
)
)
}

@Test
def testYear(): Unit = {
checkResult(
Expand Down