@@ -31,12 +31,13 @@ class DateExpressionsFunctionalTest extends AbstractExpressionsFunctionalTest {
3131 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/#date-expression-operators
3232
3333 private final ZonedDateTime utcDateTime = ZonedDateTime .ofInstant (Instant .parse ("2007-12-03T10:15:30.005Z" ), ZoneId .of (ZoneOffset .UTC .getId ()));
34+ private final StringExpression utc = of ("UTC" );
35+ private final DateExpression utcDateEx = of (utcDateTime .toInstant ());
3436
3537 @ Test
3638 public void literalsTest () {
3739 assertExpression (
38- utcDateTime .toInstant (),
39- of (utcDateTime .toInstant ()),
40+ utcDateTime .toInstant (), utcDateEx ,
4041 "{'$date': '2007-12-03T10:15:30.005Z'}" );
4142 }
4243
@@ -45,107 +46,107 @@ public void yearTest() {
4546 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/
4647 assertExpression (
4748 utcDateTime .get (ChronoField .YEAR ),
48- of ( utcDateTime . toInstant ()). year (),
49- "{'$year': {'$date': '2007-12-03T10:15:30.005Z'}}" );
49+ utcDateEx . year (utc ),
50+ "{'$year': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
5051 }
5152
5253 @ Test
5354 public void monthTest () {
5455 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/
5556 assertExpression (
5657 utcDateTime .get (ChronoField .MONTH_OF_YEAR ),
57- of ( utcDateTime . toInstant ()). month (),
58- "{'$month': {'$date': '2007-12-03T10:15:30.005Z'}}" );
58+ utcDateEx . month (utc ),
59+ "{'$month': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
5960 }
6061
6162 @ Test
6263 public void dayOfMonthTest () {
6364 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/
6465 assertExpression (
6566 utcDateTime .get (ChronoField .DAY_OF_MONTH ),
66- of ( utcDateTime . toInstant ()). dayOfMonth (),
67- "{'$dayOfMonth': {'$date': '2007-12-03T10:15:30.005Z'}}" );
67+ utcDateEx . dayOfMonth (utc ),
68+ "{'$dayOfMonth': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
6869 }
6970
7071 @ Test
7172 public void dayOfWeekTest () {
7273 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/
7374 assertExpression (
7475 utcDateTime .get (ChronoField .DAY_OF_WEEK ) + 1 ,
75- of ( utcDateTime . toInstant ()). dayOfWeek (),
76- "{'$dayOfWeek': {'$date': '2007-12-03T10:15:30.005Z'}}" );
76+ utcDateEx . dayOfWeek (utc ),
77+ "{'$dayOfWeek': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
7778 }
7879
7980 @ Test
8081 public void dayOfYearTest () {
8182 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/
8283 assertExpression (
8384 utcDateTime .get (ChronoField .DAY_OF_YEAR ),
84- of ( utcDateTime . toInstant ()). dayOfYear (),
85- "{'$dayOfYear': {'$date': '2007-12-03T10:15:30.005Z'}}" );
85+ utcDateEx . dayOfYear (utc ),
86+ "{'$dayOfYear': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
8687 }
8788
8889 @ Test
8990 public void hourTest () {
9091 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/
9192 assertExpression (
9293 utcDateTime .get (ChronoField .HOUR_OF_DAY ),
93- of ( utcDateTime . toInstant ()). hour (),
94- "{'$hour': {'$date': '2007-12-03T10:15:30.005Z'}}" );
94+ utcDateEx . hour (utc ),
95+ "{'$hour': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
9596 }
9697
9798 @ Test
9899 public void minuteTest () {
99100 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/
100101 assertExpression (
101102 utcDateTime .get (ChronoField .MINUTE_OF_HOUR ),
102- of ( utcDateTime . toInstant ()). minute (),
103- "{'$minute': {'$date': '2007-12-03T10:15:30.005Z'}}" );
103+ utcDateEx . minute (utc ),
104+ "{'$minute': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
104105 }
105106
106107 @ Test
107108 public void secondTest () {
108109 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/
109110 assertExpression (
110111 utcDateTime .get (ChronoField .SECOND_OF_MINUTE ),
111- of ( utcDateTime . toInstant ()). second (),
112- "{'$second': {'$date': '2007-12-03T10:15:30.005Z'}}" );
112+ utcDateEx . second (utc ),
113+ "{'$second': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
113114 }
114115
115116 @ Test
116117 public void weekTest () {
117118 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/
118119 assertExpression (
119120 48 ,
120- of ( utcDateTime . toInstant ()). week (),
121- "{'$week': {'$date': '2007-12-03T10:15:30.005Z'}}" );
121+ utcDateEx . week (utc ),
122+ "{'$week': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
122123 }
123124
124125 @ Test
125126 public void millisecondTest () {
126127 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/
127128 assertExpression (
128129 utcDateTime .get (ChronoField .MILLI_OF_SECOND ),
129- of ( utcDateTime . toInstant ()). millisecond (),
130- "{'$millisecond': {'$date': '2007-12-03T10:15:30.005Z'}}" );
130+ utcDateEx . millisecond (utc ),
131+ "{'$millisecond': {'date': {' $date': '2007-12-03T10:15:30.005Z'}, 'timezone': 'UTC '}}" );
131132 }
132133
133134 @ Test
134135 public void dateToStringTest () {
135136 // https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/
136137 assertExpression (
137138 utcDateTime .toInstant ().toString (),
138- of ( utcDateTime . toInstant ()). dateToString ());
139+ utcDateEx . dateToString (utc ));
139140 // with parameters
140141 assertExpression (
141142 utcDateTime .withZoneSameInstant (ZoneId .of ("America/New_York" )).format (ISO_LOCAL_DATE_TIME ),
142- of ( utcDateTime . toInstant ()). dateToString (of ("%Y-%m-%dT%H:%M:%S.%L" ), of ( "America/New_York " )),
143+ utcDateEx . dateToString (of ("America/New_York" ), of ( " %Y-%m-%dT%H:%M:%S.%L" )),
143144 "{'$dateToString': {'date': {'$date': '2007-12-03T10:15:30.005Z'}, "
144145 + "'format': '%Y-%m-%dT%H:%M:%S.%L', "
145146 + "'timezone': 'America/New_York'}}" );
146147 assertExpression (
147148 utcDateTime .withZoneSameInstant (ZoneId .of ("+04:30" )).format (ISO_LOCAL_DATE_TIME ),
148- of ( utcDateTime . toInstant ()). dateToString (of ("%Y-%m-%dT%H:%M:%S.%L" ), of ( "+04:30 " )),
149+ utcDateEx . dateToString (of ("+04:30" ), of ( " %Y-%m-%dT%H:%M:%S.%L" )),
149150 "{'$dateToString': {'date': {'$date': '2007-12-03T10:15:30.005Z'}, "
150151 + "'format': '%Y-%m-%dT%H:%M:%S.%L', "
151152 + "'timezone': '+04:30'}}" );
0 commit comments