File tree 3 files changed +49
-0
lines changed
main/java/org/apache/struts2/components
test/java/org/apache/struts2
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,8 @@ public boolean end(Writer writer, String body) {
308
308
date = ((LocalDateTime ) dateObject ).atZone (tz );
309
309
} else if (dateObject instanceof LocalDate ) {
310
310
date = ((LocalDate ) dateObject ).atStartOfDay (tz );
311
+ } else if (dateObject instanceof LocalTime ) {
312
+ date = ((LocalTime ) dateObject ).atDate (ZonedDateTime .now (tz ).toLocalDate ()).atZone (tz );
311
313
} else if (dateObject instanceof Instant ) {
312
314
date = ((Instant ) dateObject ).atZone (tz );
313
315
} else {
Original file line number Diff line number Diff line change 28
28
import java .io .Writer ;
29
29
import java .text .DateFormat ;
30
30
import java .text .SimpleDateFormat ;
31
+ import java .time .format .DateTimeFormatter ;
31
32
import java .util .Map ;
32
33
33
34
public class DateTest extends StrutsInternalTestCase {
@@ -127,6 +128,30 @@ public void testJavaSqlTime() {
127
128
assertEquals (expected , writer .toString ());
128
129
}
129
130
131
+ public void testJavaLocalTime () {
132
+ // given
133
+ Date date = new Date (stack );
134
+ date .setDateFormatter (new SimpleDateFormatAdapter ());
135
+
136
+ java .time .LocalTime now = java .time .LocalTime .now ();
137
+
138
+ String timeFormat = "hh:mm:ss" ;
139
+ String expected = DateTimeFormatter .ofPattern (timeFormat ).format (now );
140
+ context .put ("myTime" , now );
141
+
142
+ Writer writer = new StringWriter ();
143
+
144
+ // when
145
+ date .setName ("myTime" );
146
+ date .setNice (false );
147
+ date .setFormat (timeFormat );
148
+ date .start (writer );
149
+ date .end (writer , "" );
150
+
151
+ // then
152
+ assertEquals (expected , writer .toString ());
153
+ }
154
+
130
155
private DateFormat prepareFormat () {
131
156
return SimpleDateFormat .getDateTimeInstance (DateFormat .MEDIUM , DateFormat .MEDIUM , ActionContext .getContext ().getLocale ());
132
157
}
Original file line number Diff line number Diff line change 30
30
import java .time .Instant ;
31
31
import java .time .LocalDate ;
32
32
import java .time .LocalDateTime ;
33
+ import java .time .LocalTime ;
33
34
import java .time .ZoneId ;
34
35
import java .time .format .DateTimeFormatter ;
35
36
import java .util .Calendar ;
@@ -993,6 +994,27 @@ public void testNewJava8Format() throws Exception {
993
994
strutsBodyTagsAreReflectionEqual (tag , freshTag ));
994
995
}
995
996
997
+ public void testJavaLocalTime () throws Exception {
998
+ String format = "hh:mm" ;
999
+ LocalTime now = LocalTime .now ();
1000
+ String formatted = DateTimeFormatter .ofPattern (format , ActionContext .getContext ().getLocale ()).format (now );
1001
+ context .put ("myTime" , now );
1002
+
1003
+ tag .setName ("myTime" );
1004
+ tag .setNice (false );
1005
+ tag .setFormat (format );
1006
+ tag .doStartTag ();
1007
+ tag .doEndTag ();
1008
+ assertEquals (formatted , writer .toString ());
1009
+
1010
+ // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
1011
+ DateTag freshTag = new DateTag ();
1012
+ freshTag .setPageContext (pageContext );
1013
+ assertFalse ("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set. " +
1014
+ "May indicate that clearTagStateForTagPoolingServers() calls are not working properly." ,
1015
+ strutsBodyTagsAreReflectionEqual (tag , freshTag ));
1016
+ }
1017
+
996
1018
/**
997
1019
* Utility method to create a new {@link DateTextFieldTag} instance for code coverage tests.
998
1020
* <p>
You can’t perform that action at this time.
0 commit comments