karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [karaf] branch master updated: [KARAF-5475] Fix timezone string computation
Date Thu, 23 Nov 2017 12:11:53 GMT
This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new a23ee51  [KARAF-5475] Fix timezone string computation
a23ee51 is described below

commit a23ee51742dbefab22810d0803ffd1aeff2b8df8
Author: Guillaume Nodet <gnodet@gmail.com>
AuthorDate: Thu Nov 23 13:11:37 2017 +0100

    [KARAF-5475] Fix timezone string computation
---
 .../main/java/org/apache/karaf/audit/util/FastDateFormat.java    | 4 +++-
 .../java/org/apache/karaf/audit/util/FastDateFormatTest.java     | 9 ++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/audit/src/main/java/org/apache/karaf/audit/util/FastDateFormat.java b/audit/src/main/java/org/apache/karaf/audit/util/FastDateFormat.java
index 968e4a7..0442ed7 100644
--- a/audit/src/main/java/org/apache/karaf/audit/util/FastDateFormat.java
+++ b/audit/src/main/java/org/apache/karaf/audit/util/FastDateFormat.java
@@ -82,7 +82,9 @@ public class FastDateFormat {
                 }
                 date = sb.toString();
             } else {
-                date = new SimpleDateFormat(pattern, locale).format(new Date(now));
+                SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
+                sdf.setCalendar(Calendar.getInstance(timeZone, locale));
+                date = sdf.format(new Date(now));
             }
             cache.put(pattern, date);
         }
diff --git a/audit/src/test/java/org/apache/karaf/audit/util/FastDateFormatTest.java b/audit/src/test/java/org/apache/karaf/audit/util/FastDateFormatTest.java
index c1f4ec5..aea8594 100644
--- a/audit/src/test/java/org/apache/karaf/audit/util/FastDateFormatTest.java
+++ b/audit/src/test/java/org/apache/karaf/audit/util/FastDateFormatTest.java
@@ -19,6 +19,8 @@ package org.apache.karaf.audit.util;
 import org.junit.Test;
 
 import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
@@ -36,7 +38,12 @@ public class FastDateFormatTest {
         time += TimeUnit.DAYS.toMillis(5);
         assertEquals("Nov 10", cal.getDate(time, FastDateFormat.MMM_D2));
         assertEquals("2017-11-10", cal.getDate(time, FastDateFormat.YYYY_MM_DD));
+    }
 
-
+    @Test
+    public void testTimeZone() throws Exception {
+        long time = new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-05").getTime();
+        FastDateFormat cal = new FastDateFormat(TimeZone.getTimeZone("GMT+5"), Locale.ENGLISH);
+        assertEquals("+05:00", cal.getDate(time, FastDateFormat.XXX));
     }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@karaf.apache.org" <commits@karaf.apache.org>'].

Mime
View raw message