yangys
2024-03-28 13ada1093cb8de6e31a718d2222429ded70133c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.qianwen.core.excel.extend.converters;
 
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
 
/* loaded from: blade-starter-excel-9.3.0.0-SNAPSHOT.jar:org/springblade/core/excel/extend/converters/LocalDateStringConverter.class */
public enum LocalDateStringConverter implements Converter<LocalDate> {
    INSTANCE;
 
    public Class supportJavaTypeKey() {
        return LocalDate.class;
      }
      
      public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
      }
 
    public LocalDate convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException {
        if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null)
          return LocalDate.parse(cellData.getStringValue()); 
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat());
        return LocalDate.parse(cellData.getStringValue(), formatter);
    }
 
    public CellData<String> convertToExcelData(LocalDate value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        DateTimeFormatter formatter;
        if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
            formatter = DateTimeFormatter.ISO_LOCAL_DATE;
        } else {
            formatter = DateTimeFormatter.ofPattern(contentProperty.getDateTimeFormatProperty().getFormat());
        }
        return new CellData<>(value.format(formatter));
    }
}