Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F2158200D45 for ; Thu, 23 Nov 2017 13:11:55 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id F0692160BFE; Thu, 23 Nov 2017 12:11:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 42208160BEF for ; Thu, 23 Nov 2017 13:11:55 +0100 (CET) Received: (qmail 64648 invoked by uid 500); 23 Nov 2017 12:11:54 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 64639 invoked by uid 99); 23 Nov 2017 12:11:54 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Nov 2017 12:11:54 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6EB028548D; Thu, 23 Nov 2017 12:11:53 +0000 (UTC) Date: Thu, 23 Nov 2017 12:11:53 +0000 To: "commits@karaf.apache.org" Subject: [karaf] branch master updated: [KARAF-5475] Fix timezone string computation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151143911315.19629.1195859226913966280@gitbox.apache.org> From: gnodet@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: karaf X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: a0ee11e0a56924ec5a1beba4884b202fac62f7ea X-Git-Newrev: a23ee51742dbefab22810d0803ffd1aeff2b8df8 X-Git-Rev: a23ee51742dbefab22810d0803ffd1aeff2b8df8 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Thu, 23 Nov 2017 12:11:56 -0000 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 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" '].