Fix naming of the DateTimeFormatOptions
This commit is contained in:
parent
59f268aa20
commit
09fcc18b5e
@ -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;
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -10,7 +25,7 @@ import java.util.TimeZone;
|
|||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
class DateFormattingOptions {
|
class DateTimeFormatOptions {
|
||||||
private static final TimeZone DEFAULT_TZ = TimeZone.getDefault();
|
private static final TimeZone DEFAULT_TZ = TimeZone.getDefault();
|
||||||
|
|
||||||
private String timeZone;
|
private String timeZone;
|
||||||
@ -19,7 +34,7 @@ class DateFormattingOptions {
|
|||||||
@Getter
|
@Getter
|
||||||
private String pattern;
|
private String pattern;
|
||||||
|
|
||||||
public DateFormattingOptions(String timeZone) {
|
public DateTimeFormatOptions(String timeZone) {
|
||||||
this.timeZone = timeZone;
|
this.timeZone = timeZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* 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.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class TbDate extends Date {
|
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();
|
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());
|
ZonedDateTime zdt = this.toInstant().atZone(options.getTimeZone().toZoneId());
|
||||||
DateTimeFormatter formatter;
|
DateTimeFormatter formatter;
|
||||||
if (StringUtils.isNotEmpty(options.getPattern())) {
|
if (StringUtils.isNotEmpty(options.getPattern())) {
|
||||||
@ -141,17 +140,17 @@ public class TbDate extends Date {
|
|||||||
return formatter.format(zdt);
|
return formatter.format(zdt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DateFormattingOptions getDateFormattingOptions(String options) {
|
private static DateTimeFormatOptions getDateFormattingOptions(String options) {
|
||||||
DateFormattingOptions opt = null;
|
DateTimeFormatOptions opt = null;
|
||||||
if (StringUtils.isNotEmpty(options)) {
|
if (StringUtils.isNotEmpty(options)) {
|
||||||
try {
|
try {
|
||||||
opt = JacksonUtil.fromString(options, DateFormattingOptions.class);
|
opt = JacksonUtil.fromString(options, DateTimeFormatOptions.class);
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
opt = new DateFormattingOptions(options);
|
opt = new DateTimeFormatOptions(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opt == null) {
|
if (opt == null) {
|
||||||
opt = new DateFormattingOptions();
|
opt = new DateTimeFormatOptions();
|
||||||
}
|
}
|
||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user