You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2022/12/29 09:54:06 UTC

[struts] branch WW-5272-time updated (df110596c -> 08de24588)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5272-time
in repository https://gitbox.apache.org/repos/asf/struts.git


    omit df110596c WW-5272 Extends <s:date/> to support java.sql.Time
     new 08de24588 WW-5272 Extends <s:date/> to support java.sql.Time

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (df110596c)
            \
             N -- N -- N   refs/heads/WW-5272-time (08de24588)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/struts2/components/date/SimpleDateFormatAdapter.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[struts] 01/01: WW-5272 Extends to support java.sql.Time

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5272-time
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 08de24588ad5b88ec3554b476c9d3cf0fb47b32c
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Dec 28 10:13:04 2022 +0100

    WW-5272 Extends <s:date/> to support java.sql.Time
---
 .../java/org/apache/struts2/components/Date.java   |  5 +++-
 .../components/date/SimpleDateFormatAdapter.java   |  2 +-
 .../org/apache/struts2/components/DateTest.java    | 32 ++++++++++++++++++++--
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/components/Date.java b/core/src/main/java/org/apache/struts2/components/Date.java
index 7a8cda061..de640cbda 100644
--- a/core/src/main/java/org/apache/struts2/components/Date.java
+++ b/core/src/main/java/org/apache/struts2/components/Date.java
@@ -32,6 +32,7 @@ import java.io.Writer;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
@@ -294,7 +295,9 @@ public class Date extends ContextBean {
         // find the name on the valueStack
         Object dateObject = findValue(name);
         if (dateObject instanceof java.sql.Date) {
-            date = ((java.sql.Date) dateObject).toLocalDate().atStartOfDay(tz);
+            date = ((java.sql.Date) dateObject).toLocalDate().atTime(LocalTime.now(tz)).atZone(tz);
+        } else if (dateObject instanceof java.sql.Time) {
+            date = ((java.sql.Time) dateObject).toLocalTime().atDate(ZonedDateTime.now(tz).toLocalDate()).atZone(tz);
         } else if (dateObject instanceof java.util.Date) {
             date = ((java.util.Date) dateObject).toInstant().atZone(tz);
         } else if (dateObject instanceof Calendar) {
diff --git a/core/src/main/java/org/apache/struts2/components/date/SimpleDateFormatAdapter.java b/core/src/main/java/org/apache/struts2/components/date/SimpleDateFormatAdapter.java
index 38f3c5296..b7cf5441a 100644
--- a/core/src/main/java/org/apache/struts2/components/date/SimpleDateFormatAdapter.java
+++ b/core/src/main/java/org/apache/struts2/components/date/SimpleDateFormatAdapter.java
@@ -34,7 +34,7 @@ public class SimpleDateFormatAdapter implements DateFormatter {
         DateFormat df;
         Locale locale = ActionContext.getContext().getLocale();
         if (format == null) {
-            df = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, locale);
+            df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
         } else {
             df = new SimpleDateFormat(format, locale);
         }
diff --git a/core/src/test/java/org/apache/struts2/components/DateTest.java b/core/src/test/java/org/apache/struts2/components/DateTest.java
index ffe01a52a..477b128a6 100644
--- a/core/src/test/java/org/apache/struts2/components/DateTest.java
+++ b/core/src/test/java/org/apache/struts2/components/DateTest.java
@@ -66,7 +66,7 @@ public class DateTest extends StrutsInternalTestCase {
 
         java.util.Date now = new java.util.Date();
 
-        String expected = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, ActionContext.getContext().getLocale()).format(now);
+        String expected = prepareFormat().format(now);
         context.put("myDate", now);
 
         Writer writer = new StringWriter();
@@ -88,7 +88,7 @@ public class DateTest extends StrutsInternalTestCase {
 
         java.sql.Date now = new java.sql.Date(System.currentTimeMillis());
 
-        String expected = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, ActionContext.getContext().getLocale()).format(now);
+        String expected = prepareFormat().format(now);
         context.put("myDate", now);
 
         Writer writer = new StringWriter();
@@ -103,6 +103,34 @@ public class DateTest extends StrutsInternalTestCase {
         assertEquals(expected, writer.toString());
     }
 
+    public void testJavaSqlTime() {
+        // given
+        Date date = new Date(stack);
+        date.setDateFormatter(new SimpleDateFormatAdapter());
+
+        java.sql.Time now = new java.sql.Time(System.currentTimeMillis());
+
+        String timeFormat = "hh:mm:ss";
+        String expected = new SimpleDateFormat(timeFormat, ActionContext.getContext().getLocale()).format(now);
+        context.put("myDate", now);
+
+        Writer writer = new StringWriter();
+
+        // when
+        date.setName("myDate");
+        date.setNice(false);
+        date.setFormat(timeFormat);
+        date.start(writer);
+        date.end(writer, "");
+
+        // then
+        assertEquals(expected, writer.toString());
+    }
+
+    private DateFormat prepareFormat() {
+        return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, ActionContext.getContext().getLocale());
+    }
+
     @Override
     public void setUp() throws Exception {
         super.setUp();