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