Skip to content

Commit bc8ccf5

Browse files
committed
fix: fix the date formatting for date strings for DoB
1 parent 63bd8c2 commit bc8ccf5

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

application/CohortManager/src/Web/app/data/mockExceptions.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ExceptionDetails": {
1616
"GivenName": "William",
1717
"FamilyName": "Taylor",
18-
"DateOfBirth": "19830507",
18+
"DateOfBirth": "1983-05-07",
1919
"ParticipantAddressLine1": "258 Willow Road",
2020
"ParticipantAddressLine2": "",
2121
"ParticipantAddressLine3": "Suburb",
@@ -47,7 +47,7 @@
4747
"ExceptionDetails": {
4848
"GivenName": "Alice",
4949
"FamilyName": "Smith",
50-
"DateOfBirth": "19800101",
50+
"DateOfBirth": "1980-01-01",
5151
"ParticipantAddressLine1": "123 Main Street",
5252
"ParticipantAddressLine2": "Flat 2B",
5353
"ParticipantAddressLine3": "Central District",
@@ -79,7 +79,7 @@
7979
"ExceptionDetails": {
8080
"GivenName": "Alice",
8181
"FamilyName": "Smith",
82-
"DateOfBirth": "19800101",
82+
"DateOfBirth": "1980-01-01",
8383
"ParticipantAddressLine1": "123 Main Street",
8484
"ParticipantAddressLine2": "Flat 2B",
8585
"ParticipantAddressLine3": "Central District",
@@ -111,7 +111,7 @@
111111
"ExceptionDetails": {
112112
"GivenName": "Bob",
113113
"FamilyName": "Johnson",
114-
"DateOfBirth": "19751212",
114+
"DateOfBirth": "1975-12-12",
115115
"ParticipantAddressLine1": "456 Oak Avenue",
116116
"ParticipantAddressLine2": "",
117117
"ParticipantAddressLine3": "West End",
@@ -143,7 +143,7 @@
143143
"ExceptionDetails": {
144144
"GivenName": "Alice",
145145
"FamilyName": "Smith",
146-
"DateOfBirth": "19800101",
146+
"DateOfBirth": "1980-01-01",
147147
"ParticipantAddressLine1": "123 Main Street",
148148
"ParticipantAddressLine2": "Flat 2B",
149149
"ParticipantAddressLine3": "Central District",
@@ -175,7 +175,7 @@
175175
"ExceptionDetails": {
176176
"GivenName": "Emma",
177177
"FamilyName": "Wilson",
178-
"DateOfBirth": "19850315",
178+
"DateOfBirth": "1985-03-15",
179179
"ParticipantAddressLine1": "789 Elm Street",
180180
"ParticipantAddressLine2": "Apt 5C",
181181
"ParticipantAddressLine3": "Downtown",
@@ -207,7 +207,7 @@
207207
"ExceptionDetails": {
208208
"GivenName": "Oliver",
209209
"FamilyName": "Brown",
210-
"DateOfBirth": "19920628",
210+
"DateOfBirth": "1992-06-28",
211211
"ParticipantAddressLine1": "321 Pine Road",
212212
"ParticipantAddressLine2": "",
213213
"ParticipantAddressLine3": "Northside",
@@ -239,7 +239,7 @@
239239
"ExceptionDetails": {
240240
"GivenName": "Sophia",
241241
"FamilyName": "Davis",
242-
"DateOfBirth": "19781104",
242+
"DateOfBirth": "1978-11-04",
243243
"ParticipantAddressLine1": "654 Cedar Lane",
244244
"ParticipantAddressLine2": "House 12",
245245
"ParticipantAddressLine3": "Eastside",
@@ -271,7 +271,7 @@
271271
"ExceptionDetails": {
272272
"GivenName": "James",
273273
"FamilyName": "Miller",
274-
"DateOfBirth": "19880719",
274+
"DateOfBirth": "1988-07-19",
275275
"ParticipantAddressLine1": "987 Maple Avenue",
276276
"ParticipantAddressLine2": "Floor 3",
277277
"ParticipantAddressLine3": "Westside",
@@ -303,7 +303,7 @@
303303
"ExceptionDetails": {
304304
"GivenName": "Charlotte",
305305
"FamilyName": "Anderson",
306-
"DateOfBirth": "19901223",
306+
"DateOfBirth": "1990-12-23",
307307
"ParticipantAddressLine1": "147 Birch Street",
308308
"ParticipantAddressLine2": "Unit B",
309309
"ParticipantAddressLine3": "City Centre",
@@ -335,7 +335,7 @@
335335
"ExceptionDetails": {
336336
"GivenName": "William",
337337
"FamilyName": "Taylor",
338-
"DateOfBirth": "19830507",
338+
"DateOfBirth": "1983-05-07",
339339
"ParticipantAddressLine1": "258 Willow Road",
340340
"ParticipantAddressLine2": "",
341341
"ParticipantAddressLine3": "Suburb",
@@ -367,7 +367,7 @@
367367
"ExceptionDetails": {
368368
"GivenName": "Isabella",
369369
"FamilyName": "Thomas",
370-
"DateOfBirth": "19940812",
370+
"DateOfBirth": "1994-08-12",
371371
"ParticipantAddressLine1": "369 Ash Grove",
372372
"ParticipantAddressLine2": "Flat 7A",
373373
"ParticipantAddressLine3": "Old Town",

application/CohortManager/src/Web/app/lib/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("formatDate", () => {
3030

3131
describe("formatCompactDate", () => {
3232
it("should format the date as 26 February 1993", () => {
33-
const input = "19930226";
33+
const input = "1993-02-26";
3434
const expectedOutput = "26 February 1993";
3535
expect(formatCompactDate(input)).toBe(expectedOutput);
3636
});

application/CohortManager/src/Web/app/lib/utils.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const formatNhsNumber = (nhsNumber: string | number): string => {
2-
if (!nhsNumber) return '';
2+
if (!nhsNumber) return "";
33
const nhsString = String(nhsNumber);
44
return nhsString.replace(/(\d{3})(\d{3})(\d{4})/, "$1 $2 $3");
55
};
@@ -17,26 +17,14 @@ export const formatDate = (dateString: string): string => {
1717
export const formatCompactDate = (dateString: string): string => {
1818
if (!dateString) return "";
1919

20-
let year: string, month: string, day: string;
21-
22-
if (dateString.includes('-') || dateString.includes('/')) {
23-
const parts = dateString.split(/[-/]/);
24-
if (parts.length !== 3) return "";
25-
[year, month, day] = parts;
26-
} else {
27-
if (dateString.length < 8) return "";
28-
year = dateString.slice(0, 4);
29-
month = dateString.slice(4, 6);
30-
day = dateString.slice(6, 8);
31-
}
20+
const date = new Date(dateString);
3221

33-
const date = new Date(`${year}-${month}-${day}`);
34-
if (isNaN(date.getTime())) return "";
3522
const options: Intl.DateTimeFormatOptions = {
36-
year: "numeric",
37-
month: "long",
3823
day: "numeric",
24+
month: "long",
25+
year: "numeric",
3926
};
27+
4028
return date.toLocaleDateString("en-GB", options);
4129
};
4230

0 commit comments

Comments
 (0)