normanj-bitquill commented on code in PR #3805:
URL: https://github.com/apache/calcite/pull/3805#discussion_r1633827873


##########
core/src/main/java/org/apache/calcite/util/format/postgresql/DateStringFormatPattern.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.util.format.postgresql;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.time.DayOfWeek;
+import java.time.Month;
+import java.time.ZonedDateTime;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+/**
+ * Converts a non numeric value from a string to a datetime component and can 
generate
+ * a string representation of of a datetime component from a datetime. An 
example is
+ * converting to and from month names.
+ *
+ * @param <T> a type used by <code>java.time</code> to represent a datetime 
component
+ *           that has a string representation
+ */
+public class DateStringFormatPattern<T> extends StringFormatPattern {
+  /**
+   * Provides an abstraction over datetime components that have string 
representations.
+   *
+   * @param <T> a type used by <code>java.time</code> to represent a datetime 
component
+   *           that has a string representation
+   */
+  private interface DateStringConverter<T> {
+    T getValueFromDateTime(ZonedDateTime dateTime);
+
+    String getDisplayName(T value, TextStyle textStyle, boolean haveFillMode, 
Locale locale);
+  }
+
+  /**
+   * Can convert between a day of week name and the corresponding datetime 
component value.
+   */
+  private static class DayOfWeekConverter implements 
DateStringConverter<DayOfWeek> {
+    @Override public DayOfWeek getValueFromDateTime(ZonedDateTime dateTime) {
+      return dateTime.getDayOfWeek();
+    }
+
+    @Override public String getDisplayName(DayOfWeek value, TextStyle 
textStyle,
+        boolean haveFillMode, Locale locale) {
+      final String formattedValue = value.getDisplayName(textStyle, locale);
+
+      if (!haveFillMode && textStyle == TextStyle.FULL) {
+        return String.format(locale, "%-9s", formattedValue);

Review Comment:
   @mihaibudiu Added comments to explain this in the code.



-- 
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: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to