PC
2024-03-31 608f20e0d5d8f95d9bbb917e95e2913682deb77d
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
41
42
43
44
45
46
47
package com.qianwen.core.tool.time;
 
import java.util.Date;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
 
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/time/DefaultDateFormatter.class */
public class DefaultDateFormatter implements DateFormatter {
    private DateTimeFormatter formatter;
    private Predicate<String> predicate;
    private String formatterString;
 
    public DefaultDateFormatter(Pattern formatPattern, String formatter) {
        this(str -> {
            return formatPattern.matcher(str).matches();
        }, DateTimeFormat.forPattern(formatter));
        this.formatterString = formatter;
    }
 
    public DefaultDateFormatter(Predicate<String> predicate, DateTimeFormatter formatter) {
        this.predicate = predicate;
        this.formatter = formatter;
    }
 
    @Override // org.springblade.core.tool.time.DateFormatter
    public boolean support(String str) {
        return this.predicate.test(str);
    }
 
    @Override // org.springblade.core.tool.time.DateFormatter
    public Date format(String str) {
        return this.formatter.parseDateTime(str).toDate();
    }
 
    @Override // org.springblade.core.tool.time.DateFormatter
    public String getPattern() {
        return this.formatterString;
    }
 
    @Override // org.springblade.core.tool.time.DateFormatter
    public String toString(Date date) {
        return new DateTime(date).toString(getPattern());
    }
}