Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix how no abs period data in view rtn vers shown
https://eaflood.atlassian.net/browse/WATER-4886 When attempting to run the North East two-part tariff bill run for 2023-24, the B&D team got an error. When we dug in, we found it was due to a licence having a return log with no abstraction period. The return log had no abstraction period because the return requirement it was based on didn't have an abstraction period set. But when you view the problem return version, the abstraction period is displayed as **From 30 November to 30 November**. After debugging the issue, we traced the issue to how [new Date()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) handles nulls. ```javascript const abstractionDay = null const abstractionMonth = null const abstractionDate = new Date(1970, abstractionMonth - 1, abstractionDay) console.log(abstractionDate) // 1969-11-30T00:00:00.000Z const formattedAbstractionDate = abstractionDate.toLocaleDateString('en-GB', { day: 'numeric', month: 'long' }) console.log(formattedAbstractionDate) // 30 November const raw = new Date(1970, +0 - 1, +0) console.log(raw) // 1969-11-30T00:00:00.000Z ``` Rather than through an error it converts them to `+0`. The end result when we have no abstraction period data is we are calling `new Date(1970, +0 - 1, +0)`, hence always returning **30 November**. This change updates `formatAbstractionDate()` to return `null` if passed null data. Then in the view return version page we use this to determine that we need to display `Not given` instead (this is what the legacy page shows for return logs with no abstraction period data).
- Loading branch information