tanclary commented on code in PR #3653:
URL: https://github.com/apache/calcite/pull/3653#discussion_r1467990040
##########
core/src/main/java/org/apache/calcite/util/format/FormatElementEnum.java:
##########
@@ -132,17 +133,41 @@ public enum FormatElementEnum implements FormatElement {
sb.append(String.format(Locale.ROOT, "%02d",
calendar.get(Calendar.HOUR_OF_DAY)));
}
},
+ ID("u", "The weekday (Monday as the first day of the week) as a decimal
number (1-7)") {
+ @Override public void format(StringBuilder sb, Date date) {
+ final Calendar calendar = Work.get().calendar;
+ calendar.setTime(date);
+ int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
+ sb.append(String.format(Locale.ROOT, "%d", weekDay == 1 ? 7 : weekDay -
1));
Review Comment:
Does this just convert from Sunday being 1 to Monday being 1?
##########
core/src/main/java/org/apache/calcite/util/format/FormatElementEnum.java:
##########
@@ -132,17 +133,41 @@ public enum FormatElementEnum implements FormatElement {
sb.append(String.format(Locale.ROOT, "%02d",
calendar.get(Calendar.HOUR_OF_DAY)));
}
},
+ ID("u", "The weekday (Monday as the first day of the week) as a decimal
number (1-7)") {
+ @Override public void format(StringBuilder sb, Date date) {
+ final Calendar calendar = Work.get().calendar;
+ calendar.setTime(date);
+ int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
+ sb.append(String.format(Locale.ROOT, "%d", weekDay == 1 ? 7 : weekDay -
1));
+ }
+ },
// TODO: Ensure ISO 8601 for parsing
IW("w", "The ISO 8601 week number of the year (Monday as the first day of
the week) "
- + "as a decimal number (01-53)") {
+ + "as a decimal number (01-53). If the week containing January 1 has
four or more days "
+ + "in the new year, then it is week 1; otherwise it is week 53 of the
previous year, "
+ + "and the next week is week 1.") {
@Override public void format(StringBuilder sb, Date date) {
- // TODO: ensure this is isoweek
- final Calendar calendar = Work.get().calendar;
+ final Calendar calendar = Work.get().iso8601Calendar;
calendar.setTime(date);
- calendar.setFirstDayOfWeek(Calendar.MONDAY);
sb.append(String.format(Locale.ROOT, "%02d",
calendar.get(Calendar.WEEK_OF_YEAR)));
}
},
+ IYY("YY", "The ISO 8601 year without century as a decimal number. Each ISO
year begins on "
+ + "the Monday before the first Thursday of the Gregorian calendar
year.") {
Review Comment:
Should we add some tests to `FormatElementEnumTest`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]