mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4705 - Add support for long type to <s:date> tag
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user