Skip to content
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

[Backport 2.x] Support More Formats For GET_FORMAT Function #1349

Merged
merged 1 commit into from
Feb 16, 2023
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 @@ -106,12 +106,27 @@ public class DateTimeFunction {
// Map used to determine format output for the get_format function
private static final Table<String, String, String> formats =
ImmutableTable.<String, String, String>builder()
//TODO: Add support for other formats
.put("date", "usa", "%m.%d.%Y")
.put("time", "usa", "%h:%i:%s %p")
.put("datetime", "usa", "%Y-%m-%d %H.%i.%s")
.put("timestamp", "usa", "%Y-%m-%d %H.%i.%s")
.build();
.put("date", "usa", "%m.%d.%Y")
.put("date", "jis", "%Y-%m-%d")
.put("date", "iso", "%Y-%m-%d")
.put("date", "eur", "%d.%m.%Y")
.put("date", "internal", "%Y%m%d")
.put("datetime", "usa", "%Y-%m-%d %H.%i.%s")
.put("datetime", "jis", "%Y-%m-%d %H:%i:%s")
.put("datetime", "iso", "%Y-%m-%d %H:%i:%s")
.put("datetime", "eur", "%Y-%m-%d %H.%i.%s")
.put("datetime", "internal", "%Y%m%d%H%i%s")
.put("time", "usa", "%h:%i:%s %p")
.put("time", "jis", "%H:%i:%s")
.put("time", "iso", "%H:%i:%s")
.put("time", "eur", "%H.%i.%s")
.put("time", "internal", "%H%i%s")
.put("timestamp", "usa", "%Y-%m-%d %H.%i.%s")
.put("timestamp", "jis", "%Y-%m-%d %H:%i:%s")
.put("timestamp", "iso", "%Y-%m-%d %H:%i:%s")
.put("timestamp", "eur", "%Y-%m-%d %H.%i.%s")
.put("timestamp", "internal", "%Y%m%d%H%i%s")
.build();

/**
* Register Date and Time Functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,25 @@ public void from_days() {
private static Stream<Arguments> getTestDataForGetFormat() {
return Stream.of(
Arguments.of("DATE", "USA", "%m.%d.%Y"),
Arguments.of("DATE", "JIS", "%Y-%m-%d"),
Arguments.of("DATE", "ISO", "%Y-%m-%d"),
Arguments.of("DATE", "EUR", "%d.%m.%Y"),
Arguments.of("DATE", "INTERNAL", "%Y%m%d"),
Arguments.of("DATETIME", "USA", "%Y-%m-%d %H.%i.%s"),
Arguments.of("DATETIME", "JIS", "%Y-%m-%d %H:%i:%s"),
Arguments.of("DATETIME", "ISO", "%Y-%m-%d %H:%i:%s"),
Arguments.of("DATETIME", "EUR", "%Y-%m-%d %H.%i.%s"),
Arguments.of("DATETIME", "INTERNAL", "%Y%m%d%H%i%s"),
Arguments.of("TIME", "USA", "%h:%i:%s %p"),
Arguments.of("TIME", "JIS", "%H:%i:%s"),
Arguments.of("TIME", "ISO", "%H:%i:%s"),
Arguments.of("TIME", "EUR", "%H.%i.%s"),
Arguments.of("TIME", "INTERNAL", "%H%i%s"),
Arguments.of("TIMESTAMP", "USA", "%Y-%m-%d %H.%i.%s"),
Arguments.of("TIME", "USA", "%h:%i:%s %p")
Arguments.of("TIMESTAMP", "JIS", "%Y-%m-%d %H:%i:%s"),
Arguments.of("TIMESTAMP", "ISO", "%Y-%m-%d %H:%i:%s"),
Arguments.of("TIMESTAMP", "EUR", "%Y-%m-%d %H.%i.%s"),
Arguments.of("TIMESTAMP", "INTERNAL", "%Y%m%d%H%i%s")
);
}

Expand Down
2 changes: 1 addition & 1 deletion docs/user/dql/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ Usage: Returns a string value containing string format specifiers based on the i

Argument type: TYPE, STRING
TYPE must be one of the following tokens: [DATE, TIME, DATETIME, TIMESTAMP].
STRING must be one of the following tokens: ["USA"] (" can be replaced by ').
STRING must be one of the following tokens: ["USA", "JIS", "ISO", "EUR", "INTERNAL"] (" can be replaced by ').

Examples::

Expand Down