|
|
|
@ -1301,7 +1301,7 @@ public class ProjectionOperationUnitTests { |
|
|
|
is(JSON.parse("{ $project: { time: { $dateToString: { format: \"%H:%M:%S:%L\", date: \"$date\" } } } }"))); |
|
|
|
is(JSON.parse("{ $project: { time: { $dateToString: { format: \"%H:%M:%S:%L\", date: \"$date\" } } } }"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1834
|
|
|
|
@Test // DATAMONGO-1834, DATAMONGO-2047
|
|
|
|
public void shouldRenderDateToStringAggregationExpressionWithTimezone() { |
|
|
|
public void shouldRenderDateToStringAggregationExpressionWithTimezone() { |
|
|
|
|
|
|
|
|
|
|
|
DBObject agg = project() |
|
|
|
DBObject agg = project() |
|
|
|
@ -1310,6 +1310,13 @@ public class ProjectionOperationUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(agg, is(JSON.parse( |
|
|
|
assertThat(agg, is(JSON.parse( |
|
|
|
"{ $project: { time: { $dateToString: { format: \"%H:%M:%S:%L\", date: \"$date\", \"timezone\" : \"America/Chicago\" } } } } } }"))); |
|
|
|
"{ $project: { time: { $dateToString: { format: \"%H:%M:%S:%L\", date: \"$date\", \"timezone\" : \"America/Chicago\" } } } } } }"))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DBObject removedTimezone = project().and(DateOperators.dateOf("date") |
|
|
|
|
|
|
|
.withTimezone(Timezone.valueOf("America/Chicago")).toString("%H:%M:%S:%L").withTimezone(Timezone.none())) |
|
|
|
|
|
|
|
.as("time").toDBObject(Aggregation.DEFAULT_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(removedTimezone, |
|
|
|
|
|
|
|
is(JSON.parse("{ $project: { time: { $dateToString: { format: \"%H:%M:%S:%L\", date: \"$date\" } } } } } }"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2047
|
|
|
|
@Test // DATAMONGO-2047
|
|
|
|
@ -1323,6 +1330,29 @@ public class ProjectionOperationUnitTests { |
|
|
|
.parse("{ $project: { time: { $dateToString: { date: \"$date\", \"onNull\" : \"$fallback-field\" } } } }"))); |
|
|
|
.parse("{ $project: { time: { $dateToString: { date: \"$date\", \"onNull\" : \"$fallback-field\" } } } }"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2047
|
|
|
|
|
|
|
|
public void shouldRenderDateToStringWithOnNullExpression() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DBObject agg = project() |
|
|
|
|
|
|
|
.and(DateOperators.dateOf("date").toStringWithDefaultFormat() |
|
|
|
|
|
|
|
.onNullReturnValueOf(LiteralOperators.valueOf("my-literal").asLiteral())) |
|
|
|
|
|
|
|
.as("time").toDBObject(Aggregation.DEFAULT_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(agg, is(JSON.parse( |
|
|
|
|
|
|
|
"{ $project: { time: { $dateToString: { date: \"$date\", \"onNull\" : { \"$literal\": \"my-literal\"} } } } }"))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2047
|
|
|
|
|
|
|
|
public void shouldRenderDateToStringWithOnNullAndTimezone() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DBObject agg = project().and(DateOperators.dateOf("date").toStringWithDefaultFormat() |
|
|
|
|
|
|
|
.onNullReturnValueOf("fallback-field").withTimezone(Timezone.ofField("foo"))).as("time") |
|
|
|
|
|
|
|
.toDBObject(Aggregation.DEFAULT_CONTEXT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(agg, is(JSON.parse( |
|
|
|
|
|
|
|
"{ $project: { time: { $dateToString: { date: \"$date\", \"onNull\" : \"$fallback-field\", \"timezone\": \"$foo\" } } } }"))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1536
|
|
|
|
@Test // DATAMONGO-1536
|
|
|
|
public void shouldRenderSumAggregationExpression() { |
|
|
|
public void shouldRenderSumAggregationExpression() { |
|
|
|
|
|
|
|
|
|
|
|
|