jimu-decompiled/sources/com/thoughtworks/xstream/converters/time/LocalDateTimeConverter.java
2025-05-13 19:24:51 +02:00

39 lines
1.5 KiB
Java

package com.thoughtworks.xstream.converters.time;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
/* loaded from: classes.dex */
public class LocalDateTimeConverter implements SingleValueConverter {
private static final DateTimeFormatter FORMATTER = new DateTimeFormatterBuilder().appendPattern("uuuu-MM-dd'T'HH:mm:ss").appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).toFormatter();
@Override // com.thoughtworks.xstream.converters.ConverterMatcher
public boolean canConvert(Class cls) {
return LocalDateTime.class == cls;
}
@Override // com.thoughtworks.xstream.converters.SingleValueConverter
public Object fromString(String str) {
try {
return LocalDateTime.parse(str);
} catch (DateTimeParseException e) {
ConversionException conversionException = new ConversionException("Cannot parse value as local date time", e);
conversionException.add("value", str);
throw conversionException;
}
}
@Override // com.thoughtworks.xstream.converters.SingleValueConverter
public String toString(Object obj) {
if (obj == null) {
return null;
}
return FORMATTER.format((LocalDateTime) obj);
}
}