mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Resolved WW-3424 - added expression evaluation for timezone attribute
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@929448 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -70,6 +70,24 @@ public class DateTagTest extends AbstractTagTest {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user