Skip to content

$dateToString aggregation with timezone outputs invalid ISO8601 string #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions driver-core/src/main/com/mongodb/client/model/mql/MqlDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ public interface MqlDate extends MqlValue {
*/
MqlString asString(MqlString timezone, MqlString format);

/**
* The string representation of {@code this} date as determined by the
* provided {@code timezone} with default format as below:
*
* <ul>
* <li>If {@code timezone} is UTC timezone, {@code "%Y-%m-%dT%H:%M:%S.%LZ"} will be the default
* <li>Otherwise the default format will be {@code "%Y-%m-%dT%H:%M:%S.%L"}
* </ul>
*
* @param timezone the UTC Offset or Olson Timezone Identifier.
* @return the resulting value.
*/
MqlString asString(MqlString timezone);

/**
* The result of passing {@code this} value to the provided function.
* Equivalent to {@code f.apply(this)}, and allows lambdas and static,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.function.BinaryOperator;
import java.util.function.Function;

import static com.mongodb.assertions.Assertions.fail;
import static com.mongodb.client.model.mql.MqlValues.of;
import static com.mongodb.client.model.mql.MqlValues.ofNull;
import static com.mongodb.client.model.mql.MqlValues.ofStringArray;
Expand Down Expand Up @@ -953,6 +954,10 @@ public MqlString asString(final MqlString timezone, final MqlString format) {
.append("timezone", toBsonValue(cr, timezone))));
}

public MqlString asString(final MqlString timezone) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we do not need this method, and that it might actually be introducing the bug described in the Jira. That is, the API as it is now intentionally prevents the user from specifying a timezone without also forcing that user to explicitly specify a format, thus preventing the situation from arising.

For reference:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for sharing. Yeah, also saw you raising the point in our team slack channel. I have no objection of closing this PR.

throw fail(); // intentionally not implemented, see DRIVERS-2620
}

@Override
public MqlDate parseDate(final MqlString timezone, final MqlString format) {
Assertions.notNull("timezone", timezone);
Expand Down