Anthrino commented on code in PR #3761:
URL: https://github.com/apache/calcite/pull/3761#discussion_r1566466811
##########
core/src/main/java/org/apache/calcite/util/format/FormatElementEnum.java:
##########
@@ -253,12 +373,27 @@ public enum FormatElementEnum implements FormatElement {
sb.append(String.format(Locale.ROOT, "%02d",
calendar.get(Calendar.WEEK_OF_YEAR)));
}
},
+ Y("y", "Last digit of year") {
+ @Override public void format(StringBuilder sb, Date date) {
+ final Work work = Work.get();
+ String formattedYear = work.yyFormat.format(date);
+ sb.append(formattedYear.substring(formattedYear.length() - 1));
+ }
+ },
YY("yy", "Last 2 digits of year") {
@Override public void format(StringBuilder sb, Date date) {
final Work work = Work.get();
sb.append(work.yyFormat.format(date));
}
},
+ YYY("yyy", "Last 3 digits of year") {
+ @Override public void format(StringBuilder sb, Date date) {
+ final Calendar calendar = Work.get().calendar;
+ calendar.setTime(date);
+ String formattedYear = String.format(Locale.ROOT, "%d",
calendar.get(Calendar.YEAR));
+ sb.append(formattedYear.substring(formattedYear.length() - 3));
Review Comment:
You are right, the earlier method was reusing what was being done in `YYYY`
and cropping that down to three digits. But the `YYYY` implementation was
incorrect as it was reading an integer where the `Calendar` object stored the
year, and that would return an int value and not a formatted year with 4 digits
(showing the century number).
Corrected the `YYYY` and `YYY` functions to return a proper formatted value
in terms of digits, and added a method `pctY` to return values consistent to
what BQ returns.
--
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]