Skip to content

Commit

Permalink
Added Support For More Formats For Get_Format (#1343)
Browse files Browse the repository at this point in the history
Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
(cherry picked from commit 672c72f)
  • Loading branch information
GabeFernandez310 authored and github-actions[bot] committed Feb 16, 2023
1 parent 46026af commit aa42ce0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
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

0 comments on commit aa42ce0

Please sign in to comment.