1 | package pro.verron.officestamper.preset.resolvers.date; | |
2 | ||
3 | import pro.verron.officestamper.api.ObjectResolver; | |
4 | import pro.verron.officestamper.api.StringResolver; | |
5 | ||
6 | import java.text.SimpleDateFormat; | |
7 | import java.time.ZoneId; | |
8 | import java.time.format.DateTimeFormatter; | |
9 | import java.util.Date; | |
10 | ||
11 | /** | |
12 | * This {@link ObjectResolver} creates a formatted date {@link String} for | |
13 | * expressions that return a {@link Date} object. | |
14 | * | |
15 | * @author Joseph Verron | |
16 | * @version ${version} | |
17 | * @since 1.6.7 | |
18 | */ | |
19 | public final class DateResolver | |
20 | extends StringResolver<Date> { | |
21 | ||
22 | private final DateTimeFormatter formatter; | |
23 | ||
24 | /** | |
25 | * Creates a new DateResolver that uses the format "dd.MM.yyyy". | |
26 | */ | |
27 | public DateResolver() { | |
28 | this(DateTimeFormatter.ofPattern("dd.MM.yyyy")); | |
29 | } | |
30 | ||
31 | /** | |
32 | * Creates a new DateResolver. | |
33 | * | |
34 | * @param formatter the format to use for date formatting. See | |
35 | * {@link SimpleDateFormat}. | |
36 | */ | |
37 | public DateResolver(DateTimeFormatter formatter) { | |
38 | super(Date.class); | |
39 | this.formatter = formatter; | |
40 | } | |
41 | ||
42 | /** | |
43 | * Resolves a formatted date string for the given {@link Date} object. | |
44 | * | |
45 | * @param date the {@link Date} object to be resolved. | |
46 | * | |
47 | * @return the formatted date string. | |
48 | */ | |
49 | @Override | |
50 | protected String resolve(Date date) { | |
51 | var zone = ZoneId.systemDefault(); | |
52 | var localDate = date.toInstant() | |
53 | .atZone(zone) | |
54 | .toLocalDate(); | |
55 |
1
1. resolve : replaced return value with "" for pro/verron/officestamper/preset/resolvers/date/DateResolver::resolve → KILLED |
return formatter.format(localDate); |
56 | } | |
57 | } | |
Mutations | ||
55 |
1.1 |