Fix naming of the DateTimeFormatOptions

This commit is contained in:
Andrii Shvaika 2023-09-08 14:49:02 +03:00
parent 59f268aa20
commit 09fcc18b5e
2 changed files with 25 additions and 11 deletions

View File

@ -1,3 +1,18 @@
/**
* Copyright © 2016-2023 The Thingsboard Authors
*
* Licensed 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.thingsboard.script.api.tbel;
import lombok.Data;
@ -10,7 +25,7 @@ import java.util.TimeZone;
@NoArgsConstructor
@Data
class DateFormattingOptions {
class DateTimeFormatOptions {
private static final TimeZone DEFAULT_TZ = TimeZone.getDefault();
private String timeZone;
@ -19,7 +34,7 @@ class DateFormattingOptions {
@Getter
private String pattern;
public DateFormattingOptions(String timeZone) {
public DateTimeFormatOptions(String timeZone) {
this.timeZone = timeZone;
}

View File

@ -5,7 +5,7 @@
* 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
* 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,
@ -34,7 +34,6 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.function.BiFunction;
import java.util.function.Function;
public class TbDate extends Date {
@ -128,9 +127,9 @@ public class TbDate extends Date {
});
}
public String toLocaleString(String localeStr, String optionsStr, BiFunction<Locale, DateFormattingOptions, DateTimeFormatter> formatterBuilder) {
public String toLocaleString(String localeStr, String optionsStr, BiFunction<Locale, DateTimeFormatOptions, DateTimeFormatter> formatterBuilder) {
Locale locale = StringUtils.isNotEmpty(localeStr) ? Locale.forLanguageTag(localeStr) : Locale.getDefault();
DateFormattingOptions options = getDateFormattingOptions(optionsStr);
DateTimeFormatOptions options = getDateFormattingOptions(optionsStr);
ZonedDateTime zdt = this.toInstant().atZone(options.getTimeZone().toZoneId());
DateTimeFormatter formatter;
if (StringUtils.isNotEmpty(options.getPattern())) {
@ -141,17 +140,17 @@ public class TbDate extends Date {
return formatter.format(zdt);
}
private static DateFormattingOptions getDateFormattingOptions(String options) {
DateFormattingOptions opt = null;
private static DateTimeFormatOptions getDateFormattingOptions(String options) {
DateTimeFormatOptions opt = null;
if (StringUtils.isNotEmpty(options)) {
try {
opt = JacksonUtil.fromString(options, DateFormattingOptions.class);
opt = JacksonUtil.fromString(options, DateTimeFormatOptions.class);
} catch (IllegalArgumentException iae) {
opt = new DateFormattingOptions(options);
opt = new DateTimeFormatOptions(options);
}
}
if (opt == null) {
opt = new DateFormattingOptions();
opt = new DateTimeFormatOptions();
}
return opt;
}