kwin commented on a change in pull request #11:
URL:
https://github.com/apache/sling-org-apache-sling-scripting-sightly/pull/11#discussion_r673036051
##########
File path:
src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/FormatFilterExtension.java
##########
@@ -77,12 +81,14 @@ public Object call(final RenderContext renderContext,
Object... arguments) {
if (hasPlaceHolders) {
return getFormattedString(runtimeObjectModel, source,
formatObject);
}
+
try {
- // somebody will hate me for this
- new SimpleDateFormat(source);
+ // try to parse as DateTimeFormatter
Review comment:
@raducotescu Can you answer this?
##########
File path:
src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/FormatFilterExtension.java
##########
@@ -176,47 +187,39 @@ private String toString(RuntimeObjectModel
runtimeObjectModel, Object[] params,
return "";
}
- private int getPredefinedFormattingStyleFromValue(String value) {
+ private FormatStyle getPredefinedFormattingStyleFromValue(String value) {
switch (value.toLowerCase(Locale.ROOT)) {
case "default":
- return DateFormat.DEFAULT;
- case "short":
- return DateFormat.SHORT;
case "medium":
- return DateFormat.MEDIUM;
+ return FormatStyle.MEDIUM;
+ case "short":
+ return FormatStyle.SHORT;
case "long":
- return DateFormat.LONG;
+ return FormatStyle.LONG;
case "full":
- return DateFormat.FULL;
+ return FormatStyle.FULL;
default:
- return -1;
+ return null;
}
}
- private String formatDate(String format, Date date, Locale locale,
TimeZone timezone) {
+ private String formatDate(String format, Date date, Locale locale,
TimeZone timezone, DateTimeFormatter formatter) {
if (date == null) {
return null;
}
try {
- final DateFormat formatter;
- int formattingStyle =
getPredefinedFormattingStyleFromValue(format);
- if (formattingStyle != -1) {
- if (locale != null) {
- formatter = DateFormat.getDateInstance(formattingStyle,
locale);
+ if (formatter == null) {
Review comment:
where is this private method called with formatter != null? Why do we
need that parameter?
##########
File path:
src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/FormatFilterExtension.java
##########
@@ -77,12 +81,14 @@ public Object call(final RenderContext renderContext,
Object... arguments) {
if (hasPlaceHolders) {
return getFormattedString(runtimeObjectModel, source,
formatObject);
}
+
try {
- // somebody will hate me for this
- new SimpleDateFormat(source);
+ // try to parse as DateTimeFormatter
Review comment:
The question is rather under which circumstances do you end in this area
as there are 4 return statements before this line (which IMHO cover all
configuration options...)
##########
File path:
src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/FormatFilterExtension.java
##########
@@ -77,12 +81,14 @@ public Object call(final RenderContext renderContext,
Object... arguments) {
if (hasPlaceHolders) {
return getFormattedString(runtimeObjectModel, source,
formatObject);
}
+
try {
- // somebody will hate me for this
- new SimpleDateFormat(source);
+ // try to parse as DateTimeFormatter
Review comment:
@Buuhuu Can you make sure this is covered by your unit test?
--
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]