Skip to content

Add $dateAdd and $dateSubtract aggregation operators - #960

Open
DanShinde wants to merge 1 commit into
mongomock:developfrom
DanShinde:feature/date-add-subtract
Open

DanShinde wants to merge 1 commit into
mongomock:developfrom
DanShinde:feature/date-add-subtract

Conversation

@DanShinde

Copy link
Copy Markdown

Both operators raised "Unrecognized expression". They now support every unit MongoDB accepts (year, quarter, month, week, day, hour, minute, second, millisecond). Month-based units clamp the day to the end of the target month, as MongoDB does (2024-01-31 + 1 month = 2024-02-29). A null or missing startDate, unit or amount returns null, and invalid arguments raise OperationFailure. The timezone argument is not supported yet and raises NotImplementedError.

Fixes #910

Both operators raised "Unrecognized expression". They now support every
unit MongoDB accepts (year, quarter, month, week, day, hour, minute,
second, millisecond). Month-based units clamp the day to the end of the
target month, as MongoDB does (2024-01-31 + 1 month = 2024-02-29). A
null or missing startDate, unit or amount returns null, and invalid
arguments raise OperationFailure. The timezone argument is not
supported yet and raises NotImplementedError.

Fixes mongomock#910
@DanShinde

Copy link
Copy Markdown
Author

Note on the failing checks: both failures come from develop, not from this change.

  • test (3.9): Hatch now installs coverage>=7.11, which requires Python 3.10+, so the 3.9 job fails while installing dependencies. The other test jobs are then cancelled by fail-fast. Fix CI against current test dependencies #951 pins the test dependencies and fixes this.
  • Build & verify package: the current hatchling writes Metadata-Version: 2.5, and the older twine bundled in hynek/build-and-inspect-python-package@v2 rejects it. A clean build of develop produces the same 2.5 metadata (it passes twine check with twine 7), so bumping that action or pinning hatchling should fix it.

Locally, hatch fmt --check passes, and so does hatch test on Python 3.10–3.13 with pymongo 3, pymongo 4 and no pymongo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unrecognized expression '$dateSubtract'

1 participant