Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
erp5 erp5
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Labels
    • Labels
  • Merge requests 139
    • Merge requests 139
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedi
  • erp5erp5
  • Merge requests
  • !1768

Merged
Created Apr 07, 2023 by Nicolas Wavrant@NicolasMaintainer

erp5_core: fix addToDate when removing a month

  • Overview 4
  • Commits 1
  • Pipelines 1
  • Changes 2

The way addToDate was working with dates was not good, and creating confusion when removing 1 month from the last days of a 31-day month, as the previous day had less days than the current month:

date = DateTime(2023, 5, 31)
print date
print addToDate(date, month=-1)

2023/05/31 00:00:00 GMT+2
2023/05/01 00:00:00 GMT+2

This was even more confusing in March, with february having only 28 days:

date = DateTime(2023, 3, 31)
print date
print addToDate(date, month=-1)

2023/03/31 00:00:00 GMT+2
2023/03/03 00:00:00 GMT+2

The new behavior is to, when removing a month, if the new day of the new month is more than the number of days in month to default to the last day of the month. For exemple, removing one month from 31/05 becomes 30/04, and from there it will add/remove the days as necessary.

The real issue being that removing a month is ambiguous and can mean a different thing for different people.

For reference, the reference implementation of timedelta in python doesn't support adding months:

https://docs.python.org/3/library/datetime.html#datetime.timedelta

I hope my solution will make the more sense in ERP5's context.

Edited Apr 07, 2023 by Nicolas Wavrant
Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: fix-addToDate
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7