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