64
64
* @author Juergen Hoeller
65
65
* @author Phillip Webb
66
66
* @author Sam Brannen
67
+ * @author Kazuki Shimizu
67
68
*/
68
69
class DateTimeFormattingTests {
69
70
@@ -467,6 +468,16 @@ void testBindYearMonth() {
467
468
assertThat (binder .getBindingResult ().getFieldValue ("yearMonth" ).toString ().equals ("2007-12" )).isTrue ();
468
469
}
469
470
471
+ @ Test
472
+ public void testBindYearMonthAnnotatedPattern () {
473
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
474
+ propertyValues .add ("yearMonthAnnotatedPattern" , "12/2007" );
475
+ binder .bind (propertyValues );
476
+ assertEquals (0 , binder .getBindingResult ().getErrorCount ());
477
+ assertTrue (binder .getBindingResult ().getFieldValue ("yearMonthAnnotatedPattern" ).toString ().equals ("12/2007" ));
478
+ assertEquals (YearMonth .parse ("2007-12" ), binder .getBindingResult ().getRawFieldValue ("yearMonthAnnotatedPattern" ));
479
+ }
480
+
470
481
@ Test
471
482
void testBindMonthDay () {
472
483
MutablePropertyValues propertyValues = new MutablePropertyValues ();
@@ -557,6 +568,16 @@ void patternLocalDateWithUnsupportedPattern() {
557
568
}
558
569
}
559
570
571
+ @ Test
572
+ public void testBindMonthDayAnnotatedPattern () {
573
+ MutablePropertyValues propertyValues = new MutablePropertyValues ();
574
+ propertyValues .add ("monthDayAnnotatedPattern" , "1/3" );
575
+ binder .bind (propertyValues );
576
+ assertEquals (0 , binder .getBindingResult ().getErrorCount ());
577
+ assertTrue (binder .getBindingResult ().getFieldValue ("monthDayAnnotatedPattern" ).toString ().equals ("1/3" ));
578
+ assertEquals (MonthDay .parse ("--01-03" ), binder .getBindingResult ().getRawFieldValue ("monthDayAnnotatedPattern" ));
579
+ }
580
+
560
581
561
582
public static class DateTimeBean {
562
583
@@ -611,6 +632,12 @@ public static class DateTimeBean {
611
632
612
633
private YearMonth yearMonth ;
613
634
635
+ @ DateTimeFormat (pattern ="MM/uuuu" )
636
+ private YearMonth yearMonthAnnotatedPattern ;
637
+
638
+ @ DateTimeFormat (pattern ="M/d" )
639
+ private MonthDay monthDayAnnotatedPattern ;
640
+
614
641
private MonthDay monthDay ;
615
642
616
643
private final List <DateTimeBean > children = new ArrayList <>();
@@ -775,6 +802,14 @@ public void setYearMonth(YearMonth yearMonth) {
775
802
this .yearMonth = yearMonth ;
776
803
}
777
804
805
+ public YearMonth getYearMonthAnnotatedPattern () {
806
+ return yearMonthAnnotatedPattern ;
807
+ }
808
+
809
+ public void setYearMonthAnnotatedPattern (YearMonth yearMonthAnnotatedPattern ) {
810
+ this .yearMonthAnnotatedPattern = yearMonthAnnotatedPattern ;
811
+ }
812
+
778
813
public MonthDay getMonthDay () {
779
814
return this .monthDay ;
780
815
}
@@ -783,6 +818,14 @@ public void setMonthDay(MonthDay monthDay) {
783
818
this .monthDay = monthDay ;
784
819
}
785
820
821
+ public MonthDay getMonthDayAnnotatedPattern () {
822
+ return monthDayAnnotatedPattern ;
823
+ }
824
+
825
+ public void setMonthDayAnnotatedPattern (MonthDay monthDayAnnotatedPattern ) {
826
+ this .monthDayAnnotatedPattern = monthDayAnnotatedPattern ;
827
+ }
828
+
786
829
public List <DateTimeBean > getChildren () {
787
830
return this .children ;
788
831
}
0 commit comments