msupply-foundation / notify

"Notify" a multi channel notification scheduling tool
GNU Affero General Public License v3.0
0 stars 1 forks source link

"End of month" schedules will break after a short month #295

Open EthanMcQ-TMF opened 5 days ago

EthanMcQ-TMF commented 5 days ago

Describe the bug

The way we currently calculate the next due date for a monthly schedule will always cause truncation.

Currently we take the start of the schedule and loop through adding months until we reach a date that is beyond the current date. This will always (eventually) cause a schedule at the end of the month to truncate lower.

2024-01-31 + 1 month =>
2024-02-29 + 1 month => // rust::chrono automatically truncates to the smaller month
2024-03-29 // This should be the 31st

To Reproduce

Steps to reproduce the behaviour:

  1. Create a monthly scheduled notification for the last day of a 31 day month
  2. Wait

Expected behaviour

The notification should send on the last day of the month, each month

Additional context

This can also cause issues with "first of the month" schedules if the local timezone is ahead of UTC (e.g. NZT +12/+13) as the schedule will be processed on the server in UTC and this same truncation will happen

EthanMcQ-TMF commented 5 days ago

Not picking this up right now but I wrote a quick unit test to show the behaviour and pushed to a branch

jmbrunskill commented 5 days ago

Nice find!