@@ -46,7 +46,7 @@ void assertDateMathEquals(String toTest, String expected) {
4646
4747 void assertDateMathEquals (String toTest , String expected , long now , boolean roundUp , DateTimeZone timeZone ) {
4848 DateMathParser parser = new DateMathParser (Joda .forPattern ("dateOptionalTime" ), TimeUnit .MILLISECONDS );
49- long gotMillis = parser .parse (toTest , callable (now ), roundUp , null );
49+ long gotMillis = parser .parse (toTest , callable (now ), roundUp , timeZone );
5050 long expectedMillis = parser .parse (expected , callable (0 ));
5151 if (gotMillis != expectedMillis ) {
5252 fail ("Date math not equal\n " +
@@ -116,16 +116,27 @@ public void testRounding() {
116116 assertDateMathEquals ("2014-11-18||/y" , "2014-12-31T23:59:59.999" , 0 , true , null );
117117 assertDateMathEquals ("2014||/y" , "2014-01-01" , 0 , false , null );
118118 assertDateMathEquals ("2014||/y" , "2014-12-31T23:59:59.999" , 0 , true , null );
119+ assertDateMathEquals ("2014-01-01T00:00:00.001||/y" , "2014-12-31T23:59:59.999" , 0 , true , null );
120+ // rounding should also take into account time zone
121+ assertDateMathEquals ("2014-11-18||/y" , "2013-12-31T23:00:00.000Z" , 0 , false , DateTimeZone .forID ("CET" ));
122+ assertDateMathEquals ("2014-11-18||/y" , "2014-12-31T22:59:59.999Z" , 0 , true , DateTimeZone .forID ("CET" ));
119123
120124 assertDateMathEquals ("2014-11-18||/M" , "2014-11-01" , 0 , false , null );
121125 assertDateMathEquals ("2014-11-18||/M" , "2014-11-30T23:59:59.999" , 0 , true , null );
122126 assertDateMathEquals ("2014-11||/M" , "2014-11-01" , 0 , false , null );
123127 assertDateMathEquals ("2014-11||/M" , "2014-11-30T23:59:59.999" , 0 , true , null );
128+ assertDateMathEquals ("2014-11-18||/M" , "2014-10-31T23:00:00.000Z" , 0 , false , DateTimeZone .forID ("CET" ));
129+ assertDateMathEquals ("2014-11-18||/M" , "2014-11-30T22:59:59.999Z" , 0 , true , DateTimeZone .forID ("CET" ));
124130
125131 assertDateMathEquals ("2014-11-18T14||/w" , "2014-11-17" , 0 , false , null );
126132 assertDateMathEquals ("2014-11-18T14||/w" , "2014-11-23T23:59:59.999" , 0 , true , null );
127133 assertDateMathEquals ("2014-11-18||/w" , "2014-11-17" , 0 , false , null );
128134 assertDateMathEquals ("2014-11-18||/w" , "2014-11-23T23:59:59.999" , 0 , true , null );
135+ assertDateMathEquals ("2014-11-18||/w" , "2014-11-16T23:00:00.000Z" , 0 , false , DateTimeZone .forID ("+01:00" ));
136+ assertDateMathEquals ("2014-11-18||/w" , "2014-11-17T01:00:00.000Z" , 0 , false , DateTimeZone .forID ("-01:00" ));
137+ assertDateMathEquals ("2014-11-18||/w" , "2014-11-16T23:00:00.000Z" , 0 , false , DateTimeZone .forID ("CET" ));
138+ assertDateMathEquals ("2014-11-18||/w" , "2014-11-23T22:59:59.999Z" , 0 , true , DateTimeZone .forID ("CET" ));
139+ assertDateMathEquals ("2014-07-22||/w" , "2014-07-20T22:00:00.000Z" , 0 , false , DateTimeZone .forID ("CET" )); // with DST
129140
130141 assertDateMathEquals ("2014-11-18T14||/d" , "2014-11-18" , 0 , false , null );
131142 assertDateMathEquals ("2014-11-18T14||/d" , "2014-11-18T23:59:59.999" , 0 , true , null );
@@ -151,7 +162,7 @@ public void testRounding() {
151162 assertDateMathEquals ("2014-11-18T14:27:32||/s" , "2014-11-18T14:27:32" , 0 , false , null );
152163 assertDateMathEquals ("2014-11-18T14:27:32||/s" , "2014-11-18T14:27:32.999" , 0 , true , null );
153164 }
154-
165+
155166 void assertParseException (String msg , String date ) {
156167 try {
157168 parser .parse (date , callable (0 ));
0 commit comments