forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Switch to LGoodDatePicker (JabRef#2340)"
This reverts commit 8556e65.
- Loading branch information
Showing
5 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/net/sf/jabref/logic/util/date/EasyDateFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package net.sf.jabref.logic.util.date; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
|
||
public class EasyDateFormat { | ||
|
||
/** | ||
* The formatter objects | ||
*/ | ||
private final DateTimeFormatter dateFormatter; | ||
|
||
|
||
public EasyDateFormat(String dateFormat) { | ||
this(DateTimeFormatter.ofPattern(dateFormat)); | ||
} | ||
|
||
public EasyDateFormat(DateTimeFormatter dateFormatter) { | ||
this.dateFormatter = dateFormatter; | ||
} | ||
|
||
/** | ||
* Creates a String containing the current date (and possibly time), | ||
* formatted according to the format set in preferences under the key | ||
* "timeStampFormat". | ||
* | ||
* @return The date string. | ||
*/ | ||
public String getCurrentDate() { | ||
return getDateAt(ZonedDateTime.now()); | ||
} | ||
|
||
/** | ||
* Creates a readable Date string from the parameter date. The format is set | ||
* in preferences under the key "timeStampFormat". | ||
* | ||
* @return The formatted date string. | ||
*/ | ||
public String getDateAt(Date date) { | ||
return getDateAt(date.toInstant().atZone(ZoneId.systemDefault())); | ||
} | ||
|
||
/** | ||
* Creates a readable Date string from the parameter date. The format is set | ||
* in preferences under the key "timeStampFormat". | ||
* | ||
* @return The formatted date string. | ||
*/ | ||
public String getDateAt(ZonedDateTime dateTime) { | ||
// first use, create an instance | ||
return dateTime.format(dateFormatter); | ||
} | ||
|
||
public static EasyDateFormat fromTimeStampFormat(String timeStampFormat) { | ||
return new EasyDateFormat(timeStampFormat); | ||
} | ||
|
||
public static EasyDateFormat isoDateFormat() { | ||
return new EasyDateFormat(DateTimeFormatter.ISO_LOCAL_DATE); | ||
} | ||
} |