rorueda commented on code in PR #3653:
URL: https://github.com/apache/calcite/pull/3653#discussion_r1471099647


##########
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:
   Added a comment - don't think my suggestion would make it clearer.
   
   Looking at Postgres documentation, the `EXTRACT(DOW...` assumes Sunday = 0, 
but the format functions `to_char, to_date,...` also assume Sunday = 1 for day 
of week.



-- 
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]

Reply via email to