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

[CALCITE-6816] Support DAY_OF_WEEK_IN_MONTH function format #4182

Closed
wants to merge 1 commit into from
Closed
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 @@ -390,6 +390,14 @@ public enum FormatElementEnum implements FormatElement {
sb.append(String.format(Locale.ROOT, "%d", calendar.get(Calendar.WEEK_OF_MONTH)));
}
},
WM("WM", "The day of week number in the month (Sunday as the first day of the week) as a decimal "
+ "number (1-5)") {
@Override public void format(StringBuilder sb, Date date) {
final Calendar calendar = Work.get().calendar;
calendar.setTime(date);
sb.append(String.format(Locale.ROOT, "%d", calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)));
}
},
WW("w", "The week number of the year (Sunday as the first day of the week) as a decimal "
+ "number (00-53)") {
@Override public void format(StringBuilder sb, Date date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static org.apache.calcite.util.format.FormatElementEnum.SSSSS;
import static org.apache.calcite.util.format.FormatElementEnum.TZR;
import static org.apache.calcite.util.format.FormatElementEnum.W;
import static org.apache.calcite.util.format.FormatElementEnum.WM;
import static org.apache.calcite.util.format.FormatElementEnum.WW;
import static org.apache.calcite.util.format.FormatElementEnum.Y;
import static org.apache.calcite.util.format.FormatElementEnum.YY;
Expand Down Expand Up @@ -208,6 +209,7 @@ MI, literalElement(":"), SS, literalElement(" "),
map.put("D", D);
map.put("WW", WW);
map.put("W", W);
map.put("WM", WM);
map.put("IW", IW);
map.put("Q", Q);
map.put("AM", AMPM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,16 @@ class FormatElementEnumTest {
assertFormatElement(FormatElementEnum.SS, "2014-09-30T10:00:00Z", "00");
}

@Test void testWM() {
@Test void testW() {
assertFormatElement(FormatElementEnum.W, "2014-09-30T10:00:00Z", "5");
}

@Test void testWM() {
assertFormatElement(FormatElementEnum.WM, "2014-09-30T10:00:00Z", "5");
assertFormatElement(FormatElementEnum.WM, "2014-09-10T10:00:00Z", "2");
assertFormatElement(FormatElementEnum.WM, "2014-09-02T10:00:00Z", "1");
}

@Test void testWW() {
assertFormatElement(FormatElementEnum.WW, "2014-09-30T10:00:00Z", "40");
}
Expand Down