Skip to content

Commit a0d5c2b

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-2671 - Fix dateFromParts millisecond field name.
Use millisecond instead of milliseconds field name. Related to: https://jira.mongodb.org/browse/DOCS-10652 Original pull request: #897.
1 parent c697fe5 commit a0d5c2b

File tree

4 files changed

+62
-22
lines changed

4 files changed

+62
-22
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/DateOperators.java

+50-10
Original file line numberDiff line numberDiff line change
@@ -1829,34 +1829,74 @@ default T secondOf(AggregationExpression expression) {
18291829
}
18301830

18311831
/**
1832-
* Set the {@literal milliseconds} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
1832+
* Set the {@literal millisecond} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
18331833
* a simple value, {@link Field field reference} or {@link AggregationExpression expression}.
18341834
*
1835-
* @param milliseconds must not be {@literal null}.
1835+
* @param millisecond must not be {@literal null}.
18361836
* @return new instance.
1837-
* @throws IllegalArgumentException if given {@literal milliseconds} is {@literal null}
1837+
* @throws IllegalArgumentException if given {@literal millisecond} is {@literal null}
1838+
* @deprecated use {@link #millisecond(Object)} instead.
18381839
*/
1839-
T milliseconds(Object milliseconds);
1840+
@Deprecated
1841+
default T milliseconds(Object millisecond) {
1842+
return millisecond(millisecond);
1843+
}
1844+
1845+
/**
1846+
* Set the {@literal millisecond} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
1847+
* a simple value, {@link Field field reference} or {@link AggregationExpression expression}.
1848+
*
1849+
* @param millisecond must not be {@literal null}.
1850+
* @return new instance.
1851+
* @throws IllegalArgumentException if given {@literal millisecond} is {@literal null}
1852+
*/
1853+
T millisecond(Object millisecond);
18401854

18411855
/**
1842-
* Set the {@literal milliseconds} to the value resolved by following the given {@link Field field reference}.
1856+
* Set the {@literal millisecond} to the value resolved by following the given {@link Field field reference}.
18431857
*
18441858
* @param fieldReference must not be {@literal null}.
18451859
* @return new instance.
18461860
* @throws IllegalArgumentException if given {@literal fieldReference} is {@literal null}.
1861+
* @deprecated use {@link #millisecondOf(String)} instead.
18471862
*/
1863+
@Deprecated
18481864
default T millisecondsOf(String fieldReference) {
1865+
return millisecondOf(fieldReference);
1866+
}
1867+
1868+
/**
1869+
* Set the {@literal millisecond} to the value resolved by following the given {@link Field field reference}.
1870+
*
1871+
* @param fieldReference must not be {@literal null}.
1872+
* @return new instance.
1873+
* @throws IllegalArgumentException if given {@literal fieldReference} is {@literal null}.
1874+
*/
1875+
default T millisecondOf(String fieldReference) {
18491876
return milliseconds(Fields.field(fieldReference));
18501877
}
18511878

18521879
/**
1853-
* Set the {@literal milliseconds} to the result of the given {@link AggregationExpression expression}.
1880+
* Set the {@literal millisecond} to the result of the given {@link AggregationExpression expression}.
18541881
*
18551882
* @param expression must not be {@literal null}.
18561883
* @return new instance.
18571884
* @throws IllegalArgumentException if given {@literal expression} is {@literal null}.
1885+
* @deprecated use {@link #millisecondOf(AggregationExpression)} instead.
18581886
*/
1887+
@Deprecated
18591888
default T millisecondsOf(AggregationExpression expression) {
1889+
return millisecondOf(expression);
1890+
}
1891+
1892+
/**
1893+
* Set the {@literal milliseconds} to the result of the given {@link AggregationExpression expression}.
1894+
*
1895+
* @param expression must not be {@literal null}.
1896+
* @return new instance.
1897+
* @throws IllegalArgumentException if given {@literal expression} is {@literal null}.
1898+
*/
1899+
default T millisecondOf(AggregationExpression expression) {
18601900
return milliseconds(expression);
18611901
}
18621902
}
@@ -1971,8 +2011,8 @@ public DateFromParts second(Object second) {
19712011
}
19722012

19732013
@Override
1974-
public DateFromParts milliseconds(Object milliseconds) {
1975-
return new DateFromParts(append("milliseconds", milliseconds));
2014+
public DateFromParts millisecond(Object millisecond) {
2015+
return new DateFromParts(append("millisecond", millisecond));
19762016
}
19772017

19782018
/**
@@ -2147,8 +2187,8 @@ public IsoDateFromParts second(Object second) {
21472187
}
21482188

21492189
@Override
2150-
public IsoDateFromParts milliseconds(Object milliseconds) {
2151-
return new IsoDateFromParts(append("milliseconds", milliseconds));
2190+
public IsoDateFromParts millisecond(Object millisecond) {
2191+
return new IsoDateFromParts(append("millisecond", millisecond));
21522192
}
21532193

21542194
/**

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public class MethodReferenceNode extends ExpressionNode {
145145
map.put("dateFromString", mapArgRef().forOperator("$dateFromString") //
146146
.mappingParametersTo("dateString", "format", "timezone", "onError", "onNull"));
147147
map.put("dateFromParts", mapArgRef().forOperator("$dateFromParts").mappingParametersTo("year", "month", "day",
148-
"hour", "minute", "second", "milliseconds", "timezone"));
148+
"hour", "minute", "second", "millisecond", "timezone"));
149149
map.put("isoDateFromParts", mapArgRef().forOperator("$dateFromParts").mappingParametersTo("isoWeekYear", "isoWeek",
150-
"isoDayOfWeek", "hour", "minute", "second", "milliseconds", "timezone"));
150+
"isoDayOfWeek", "hour", "minute", "second", "millisecond", "timezone"));
151151
map.put("dateToParts", mapArgRef().forOperator("$dateToParts") //
152152
.mappingParametersTo("date", "timezone", "iso8601"));
153153
map.put("isoDayOfWeek", singleArgRef().forOperator("$isoDayOfWeek"));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1990,15 +1990,15 @@ public void shouldRenderDateFromPartsWithJustTheYear() {
19901990
assertThat(agg).isEqualTo(Document.parse("{ $project : { newDate: { $dateFromParts: { year : 2018 } } } }"));
19911991
}
19921992

1993-
@Test // DATAMONGO-1834
1993+
@Test // DATAMONGO-1834, DATAMONGO-2671
19941994
public void shouldRenderDateFromParts() {
19951995

19961996
Document agg = project()
1997-
.and(DateOperators.dateFromParts().year(2018).month(3).day(23).hour(14).minute(25).second(10).milliseconds(2))
1997+
.and(DateOperators.dateFromParts().year(2018).month(3).day(23).hour(14).minute(25).second(10).millisecond(2))
19981998
.as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
19991999

20002000
assertThat(agg).isEqualTo(Document.parse(
2001-
"{ $project : { newDate: { $dateFromParts: { year : 2018, month : 3, day : 23, hour : 14, minute : 25, second : 10, milliseconds : 2 } } } }"));
2001+
"{ $project : { newDate: { $dateFromParts: { year : 2018, month : 3, day : 23, hour : 14, minute : 25, second : 10, millisecond : 2 } } } }"));
20022002
}
20032003

20042004
@Test // DATAMONGO-1834
@@ -2021,14 +2021,14 @@ public void shouldRenderIsoDateFromPartsWithJustTheYear() {
20212021
assertThat(agg).isEqualTo(Document.parse("{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018 } } } }"));
20222022
}
20232023

2024-
@Test // DATAMONGO-1834
2024+
@Test // DATAMONGO-1834, DATAMONGO-2671
20252025
public void shouldRenderIsoDateFromParts() {
20262026

20272027
Document agg = project().and(DateOperators.dateFromParts().isoWeekYear(2018).isoWeek(12).isoDayOfWeek(5).hour(14)
2028-
.minute(30).second(42).milliseconds(2)).as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
2028+
.minute(30).second(42).millisecond(2)).as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
20292029

20302030
assertThat(agg).isEqualTo(Document.parse(
2031-
"{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018, isoWeek : 12, isoDayOfWeek : 5, hour : 14, minute : 30, second : 42, milliseconds : 2 } } } }"));
2031+
"{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018, isoWeek : 12, isoDayOfWeek : 5, hour : 14, minute : 30, second : 42, millisecond : 2 } } } }"));
20322032
}
20332033

20342034
@Test // DATAMONGO-1834

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -902,18 +902,18 @@ public void shouldRenderDateFromStringWithFormatTimezoneOnErrorAndOnNull() {
902902
"{ \"$dateFromString\" : {\"dateString\" : \"$field\", \"format\" : \"DD-MM-YYYY\", \"timezone\" : \"UTC\", \"onError\" : -1, \"onNull\" : -2}}"));
903903
}
904904

905-
@Test // DATAMONGO-2077
905+
@Test // DATAMONGO-2077, DATAMONGO-2671
906906
public void shouldRenderDateFromParts() {
907907

908908
assertThat(transform("dateFromParts(y, m, d, h, mm, s, ms, 'UTC')")).isEqualTo(Document.parse(
909-
"{ \"$dateFromParts\" : {\"year\" : \"$y\", \"month\" : \"$m\", \"day\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"milliseconds\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
909+
"{ \"$dateFromParts\" : {\"year\" : \"$y\", \"month\" : \"$m\", \"day\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"millisecond\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
910910
}
911911

912-
@Test // DATAMONGO-2077
912+
@Test // DATAMONGO-2077, DATAMONGO-2671
913913
public void shouldRenderIsoDateFromParts() {
914914

915915
assertThat(transform("isoDateFromParts(y, m, d, h, mm, s, ms, 'UTC')")).isEqualTo(Document.parse(
916-
"{ \"$dateFromParts\" : {\"isoWeekYear\" : \"$y\", \"isoWeek\" : \"$m\", \"isoDayOfWeek\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"milliseconds\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
916+
"{ \"$dateFromParts\" : {\"isoWeekYear\" : \"$y\", \"isoWeek\" : \"$m\", \"isoDayOfWeek\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"millisecond\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
917917
}
918918

919919
@Test // DATAMONGO-2077

0 commit comments

Comments
 (0)