You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/02/12 16:08:17 UTC
[text] [TEXT-113] Add an interpolator string lookup. Reuse Apache
Commons Lang's FastDateFormat.
Repository: commons-text
Updated Branches:
refs/heads/master 74b62cb12 -> fc0dd578c
[TEXT-113] Add an interpolator string lookup. Reuse Apache Commons
Lang's FastDateFormat.
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/fc0dd578
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/fc0dd578
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/fc0dd578
Branch: refs/heads/master
Commit: fc0dd578ccd92af9a0fee1908f1f05f1fe74d602
Parents: 74b62cb
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Feb 12 09:08:15 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Feb 12 09:08:15 2018 -0700
----------------------------------------------------------------------
.../org/apache/commons/text/lookup/DateStringLookup.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/fc0dd578/src/main/java/org/apache/commons/text/lookup/DateStringLookup.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/lookup/DateStringLookup.java b/src/main/java/org/apache/commons/text/lookup/DateStringLookup.java
index de37188..513b113 100644
--- a/src/main/java/org/apache/commons/text/lookup/DateStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/DateStringLookup.java
@@ -20,6 +20,8 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import org.apache.commons.lang3.time.FastDateFormat;
+
/**
* Formats the current date or the date in the LogEvent. The "key" is used as the format String.
*/
@@ -47,16 +49,16 @@ final class DateStringLookup extends AbstractStringLookup {
* @return the formatted date
*/
private String formatDate(final long date, final String format) {
- DateFormat dateFormat = null;
+ FastDateFormat dateFormat = null;
if (format != null) {
try {
- dateFormat = new SimpleDateFormat(format);
+ dateFormat = FastDateFormat.getInstance(format);
} catch (final Exception ex) {
throw IllegalArgumentExceptions.format(ex, "Invalid date format: [%s], using default", format);
}
}
if (dateFormat == null) {
- dateFormat = DateFormat.getInstance();
+ dateFormat = FastDateFormat.getInstance();
}
return dateFormat.format(new Date(date));
}