Author: lukaszlenart
Date: Wed Mar 31 09:53:00 2010
New Revision: 929448

URL: http://svn.apache.org/viewvc?rev=929448&view=rev
Log:
Resolved WW-3424 - added expression evaluation for timezone attribute

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Date.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Date.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Date.java?rev=929448&r1=929447&r2=929448&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Date.java 
(original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Date.java 
Wed Mar 31 09:53:00 2010
@@ -302,11 +302,7 @@ public class Date extends ContextBean {
                 if (nice) {
                     msg = formatTime(tp, date);
                 } else {
-                    TimeZone tz = TimeZone.getDefault();
-                    if (timezone != null) {
-                        tz = TimeZone.getTimeZone(timezone);
-                    }
-
+                    TimeZone tz = getTimeZone();
                     if (format == null) {
                         String globalFormat = null;
 
@@ -353,6 +349,19 @@ public class Date extends ContextBean {
         return super.end(writer, "");
     }
 
+    private TimeZone getTimeZone() {
+        TimeZone tz = TimeZone.getDefault();
+        if (timezone != null) {
+            timezone = stripExpressionIfAltSyntax(timezone);
+            String actualTimezone = (String) getStack().findValue(timezone, 
String.class);
+            if (actualTimezone != null) {
+                timezone = actualTimezone;
+            }
+            tz = TimeZone.getTimeZone(timezone);
+        }
+        return tz;
+    }
+
     @StrutsTagAttribute(description="Date or DateTime format pattern", 
rtexprvalue=false)
     public void setFormat(String format) {
         this.format = format;

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java?rev=929448&r1=929447&r2=929448&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/DateTagTest.java
 Wed Mar 31 09:53:00 2010
@@ -70,6 +70,24 @@ public class DateTagTest extends Abstrac
         assertEquals(formatted, writer.toString());
     }
 
+    public void testCustomFormatWithTimezoneAsExpression() throws Exception {
+        String format = "yyyy/MM/dd hh:mm:ss";
+        Date now = 
Calendar.getInstance(TimeZone.getTimeZone("UTC+2")).getTime();
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        sdf.setTimeZone(TimeZone.getTimeZone("UTC+2"));
+        String formatted = sdf.format(now);
+        context.put("myDate", now);
+        context.put("myTimezone", "UTC+2");
+
+        tag.setName("myDate");
+        tag.setNice(false);
+        tag.setFormat(format);
+        tag.setTimezone("myTimezone");
+        tag.doStartTag();
+        tag.doEndTag();
+        assertEquals(formatted, writer.toString());
+    }
+
     public void testCustomFormatCalendar() throws Exception {
         String format = "yyyy/MM/dd hh:mm:ss";
         Calendar calendar = Calendar.getInstance();


Reply via email to