11package eu .hoefel .jatex .letter ;
22
33import java .io .File ;
4+ import java .nio .file .Path ;
5+ import java .time .LocalDate ;
6+ import java .time .ZoneId ;
47import java .util .Calendar ;
58import java .util .Map ;
69
@@ -31,7 +34,7 @@ public final class KomaLetter {
3134 private String yourMail ;
3235 private String customer ;
3336 private String invoice ;
34- private Calendar date ;
37+ private LocalDate date ;
3538 private String opening ;
3639 private String closing ;
3740 private String ps ;
@@ -40,7 +43,7 @@ public final class KomaLetter {
4043
4144 private String [] body ;
4245
43- private File file ;
46+ private Path file ;
4447
4548 /** Hiding any public constructor. */
4649 private KomaLetter () {
@@ -133,11 +136,23 @@ private static Latex setup() {
133136 *
134137 * @param file the file to save to
135138 * @return the new KomaLetter
139+ * @deprecated Use {@link #as(Path)}
136140 */
141+ @ Deprecated (forRemoval = true , since = "1.3.2" )
137142 public static KomaLetter as (File file ) {
138143 return new KomaLetter ().file (file );
139144 }
140145
146+ /**
147+ * Creates a new KomaLetter bound to file.
148+ *
149+ * @param file the file to save to
150+ * @return the new KomaLetter
151+ */
152+ public static KomaLetter as (Path file ) {
153+ return new KomaLetter ().file (file );
154+ }
155+
141156 /**
142157 * Creates a new KomaLetter bound to file.
143158 *
@@ -153,8 +168,21 @@ public static KomaLetter as(String file) {
153168 *
154169 * @param file the file to save to
155170 * @return the new KomaLetter
171+ * @deprecated Use {@link #file(Path)}
156172 */
173+ @ Deprecated (forRemoval = true , since = "1.3.2" )
157174 public KomaLetter file (File file ) {
175+ this .file = file == null ? null : file .toPath ();
176+ return this ;
177+ }
178+
179+ /**
180+ * Creates a new KomaLetter bound to file.
181+ *
182+ * @param file the file to save to
183+ * @return the new KomaLetter
184+ */
185+ public KomaLetter file (Path file ) {
158186 this .file = file ;
159187 return this ;
160188 }
@@ -330,8 +358,21 @@ public KomaLetter invoice(String invoice) {
330358 *
331359 * @param date the letter date
332360 * @return the current KOMA letter instance
361+ * @deprecated Use {@link #date(LocalDate)}
333362 */
363+ @ Deprecated (forRemoval = true , since = "1.3.2" )
334364 public KomaLetter date (Calendar date ) {
365+ this .date = date == null ? null : LocalDate .ofInstant (date .toInstant (), ZoneId .systemDefault ());
366+ return this ;
367+ }
368+
369+ /**
370+ * Sets the date of the letter. Not necessary if the date of today should be used.
371+ *
372+ * @param date the letter date
373+ * @return the current KOMA letter instance
374+ */
375+ public KomaLetter date (LocalDate date ) {
335376 this .date = date ;
336377 return this ;
337378 }
@@ -399,7 +440,7 @@ public KomaLetter cc(String... cc) {
399440 * if an error occurred
400441 */
401442 public int exec () {
402- if (date == null ) date = Calendar . getInstance ();
443+ if (date == null ) date = LocalDate . now ();
403444
404445 String address = (toStreet == null ? "" : toStreet + "\\ \\ " )
405446 + (toCity == null ? "" : toCity + "\\ \\ " )
@@ -415,8 +456,8 @@ public int exec() {
415456 locale = language ;
416457 }
417458
418- Latex tex = setup ().folder (file .getParent ())
419- .filename (file .getName ());
459+ Latex tex = setup ().folder (file .getParent (). toString () )
460+ .filename (file .getFileName (). toString ());
420461
421462 if (user != null ) tex .add (user );
422463
@@ -437,8 +478,7 @@ public int exec() {
437478 .addToPreamble ("\\ setkomavar{myref}{" + (myRef == null ? "" : myRef ) + "}" )
438479 .addToPreamble ("\\ setkomavar{customer}{" + (customer == null ? "" : customer ) + "}" )
439480 .addToPreamble ("\\ setkomavar{invoice}{" + (invoice == null ? "" : invoice ) + "}" )
440- .addToPreamble ("\\ setkomavar{date}{\\ DTMdisplaydate{" + date .get (Calendar .YEAR ) + "}{"
441- + (date .get (Calendar .MONTH ) + 1 ) + "}{" + date .get (Calendar .DAY_OF_MONTH ) + "}{-1}}" )
481+ .addToPreamble ("\\ setkomavar{date}{\\ DTMdisplaydate{" +date .getYear ()+"}{" +(date .getMonthValue ())+"}{" +date .getDayOfMonth ()+"}{-1}}" )
442482 .addToPreamble (Latex .MINOR_SEPARATOR )
443483 .addToPreamble (Latex .EMPTY_LINE )
444484 .addToPreamble ("\\ layout" )
0 commit comments