Repository: struts
Updated Branches:
  refs/heads/master 8699f639f -> 8fe2bb831


WW-4705 - Add support for long type to <s:date> tag


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/8fe2bb83
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/8fe2bb83
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/8fe2bb83

Branch: refs/heads/master
Commit: 8fe2bb8317088f6a24aea3a03f19a9f257cbec09
Parents: 8699f63
Author: Aleksandr Mashchenko <amashche...@apache.org>
Authored: Tue Nov 1 19:01:44 2016 +0200
Committer: Aleksandr Mashchenko <amashche...@apache.org>
Committed: Tue Nov 1 19:01:44 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/struts2/components/Date.java     |  8 +++++---
 .../org/apache/struts2/views/jsp/ui/DateTagTest.java | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/8fe2bb83/core/src/main/java/org/apache/struts2/components/Date.java
----------------------------------------------------------------------
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 3c89ce4..ac3d68b 100644
--- a/core/src/main/java/org/apache/struts2/components/Date.java
+++ b/core/src/main/java/org/apache/struts2/components/Date.java
@@ -288,8 +288,10 @@ public class Date extends ContextBean {
             Object dateObject = findValue(name);
             if (dateObject instanceof java.util.Date) {
                 date = (java.util.Date) dateObject;
-            } else if(dateObject instanceof Calendar){
+            } else if (dateObject instanceof Calendar) {
                 date = ((Calendar) dateObject).getTime();
+            } else if (dateObject instanceof Long) {
+                date = new java.util.Date((long) dateObject);
             } else {
                 if (devMode) {
                     String developerNotification = LocalizedTextUtil.findText(
@@ -299,12 +301,12 @@ public class Date extends ContextBean {
                             "Developer Notification:\n{0}",
                             new Object[]{
                                     "Expression [" + name + "] passed to 
<s:date/> tag which was evaluated to [" + dateObject + "]("
-                                            + (dateObject != null ? 
dateObject.getClass() : "null") + ") isn't instance of java.util.Date nor 
java.util.Calendar!"
+                                            + (dateObject != null ? 
dateObject.getClass() : "null") + ") isn't instance of java.util.Date nor 
java.util.Calendar nor long!"
                             }
                     );
                     LOG.warn(developerNotification);
                 } else {
-                    LOG.debug("Expression [{}] passed to <s:date/> tag which 
was evaluated to [{}]({}) isn't instance of java.util.Date nor 
java.util.Calendar!",
+                    LOG.debug("Expression [{}] passed to <s:date/> tag which 
was evaluated to [{}]({}) isn't instance of java.util.Date nor 
java.util.Calendar nor long!",
                             name, dateObject, (dateObject != null ? 
dateObject.getClass() : "null"));
                 }
             }

http://git-wip-us.apache.org/repos/asf/struts/blob/8fe2bb83/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java 
b/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
index 27c6a0d..cc5b7a7 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
@@ -102,6 +102,21 @@ public class DateTagTest extends AbstractTagTest {
         assertEquals(formatted, writer.toString());
     }
 
+    public void testCustomFormatLong() throws Exception {
+        String format = "yyyy/MM/dd hh:mm:ss";
+        Date date = new Date();
+        String formatted = new SimpleDateFormat(format).format(date);
+        // long
+        context.put("myDate", date.getTime());
+
+        tag.setName("myDate");
+        tag.setNice(false);
+        tag.setFormat(format);
+        tag.doStartTag();
+        tag.doEndTag();
+        assertEquals(formatted, writer.toString());
+    }
+
     public void testDefaultFormat() throws Exception {
         Date now = new Date();
         String formatted = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, 
DateFormat.MEDIUM,

Reply via email to