Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken return version start date page (#1469)
* Fix broken return version start date page https://eaflood.atlassian.net/browse/WATER-4687 In [Decouple start date logic](#1461) we made a change to support adding quarterly returns. It was determined the logic for working out the start date from the values entered by the user was being duplicated in other places. The change ensured the logic stays in just the `SubmitStartDateService`, and added a new property `returnVersionStartDate` that other services could use instead. Unfortunately, an error was introduced. ```javascript // app/services/return-versions/setup/submit-start-date.service.js // Reminder! Because of the unique qualities of Javascript, Year and Day are literal values, month is an index! So, // January is actually 0, February is 1 etc. This is why we deduct 1 from the month. session.returnVersionStartDate = new Date(`${payload['start-date-year']}-${payload['start-date-month'] - 1}-${payload['start-date-day']}`).toISOString().split('T')[0] ``` This way of creating the date was added. It uses a [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) to combine the values provided by the user and pass it as an argument o JavaScript's `new Date()`. But it also applies a common fix for the fact JavaScript expects month to be provided as an index, not literally! So, January = 0, February = 1 etc. The problem is `new Date('2024-04-01')` is not the same as `new Date(2024, 4, 1)`. The first _will_ return you 1 April 2024, the second will return 1 March 2024. JavaScript understands that 'month' is literal when you provide a string argument to `new Date()`. It is only when passing month as a separate value that you have to treat it as an index. The result for the return versions setup journey is that a user is entering, for example, `13 May 2019` on the start page, but we're storing (and would eventually persist!) `13 April 2019`. This change fixes the issue. * Simplify licence start date handling We don't need to call `toISOString()` and `split()`. It works perfectly, as it has done in other places in the code without these additions. * Oops! * Fix test that masked the issue The user has entered '26 11 2023' in the UI. Therefore, they should expect to see `26 November 2023` when `returnVersionStartDate` is used or displayed anywhere in the UI. The test wasn't highlighting something was wrong because it was asserting this fact. * Fix the issue * I like spacing, but not that much!
- Loading branch information