Skip to content

Commit 332f693

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

File tree

3 files changed

+35
-46
lines changed

3 files changed

+35
-46
lines changed

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

Lines changed: 28 additions & 28 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",
@@ -399,7 +399,7 @@
399399
"ExceptionDetails": {
400400
"GivenName": "Henry",
401401
"FamilyName": "Jackson",
402-
"DateOfBirth": "19760930",
402+
"DateOfBirth": "1976-09-30",
403403
"ParticipantAddressLine1": "741 Rose Street",
404404
"ParticipantAddressLine2": "Suite 4",
405405
"ParticipantAddressLine3": "Industrial Area",
@@ -431,7 +431,7 @@
431431
"ExceptionDetails": {
432432
"GivenName": "Amelia",
433433
"FamilyName": "White",
434-
"DateOfBirth": "19870216",
434+
"DateOfBirth": "1987-02-16",
435435
"ParticipantAddressLine1": "852 Poplar Drive",
436436
"ParticipantAddressLine2": "",
437437
"ParticipantAddressLine3": "Riverside",
@@ -463,7 +463,7 @@
463463
"ExceptionDetails": {
464464
"GivenName": "Benjamin",
465465
"FamilyName": "Harris",
466-
"DateOfBirth": "19910605",
466+
"DateOfBirth": "1991-06-05",
467467
"ParticipantAddressLine1": "963 Cherry Lane",
468468
"ParticipantAddressLine2": "Apartment 9",
469469
"ParticipantAddressLine3": "Hillside",
@@ -495,7 +495,7 @@
495495
"ExceptionDetails": {
496496
"GivenName": "Mia",
497497
"FamilyName": "Martin",
498-
"DateOfBirth": "19860923",
498+
"DateOfBirth": "1986-09-23",
499499
"ParticipantAddressLine1": "174 Hazel Court",
500500
"ParticipantAddressLine2": "Block C",
501501
"ParticipantAddressLine3": "Green Park",
@@ -527,7 +527,7 @@
527527
"ExceptionDetails": {
528528
"GivenName": "Lucas",
529529
"FamilyName": "Thompson",
530-
"DateOfBirth": "19891127",
530+
"DateOfBirth": "1989-11-27",
531531
"ParticipantAddressLine1": "517 Sycamore Street",
532532
"ParticipantAddressLine2": "Ground Floor",
533533
"ParticipantAddressLine3": "Commercial District",
@@ -559,7 +559,7 @@
559559
"ExceptionDetails": {
560560
"GivenName": "Evelyn",
561561
"FamilyName": "Garcia",
562-
"DateOfBirth": "19930418",
562+
"DateOfBirth": "1993-04-18",
563563
"ParticipantAddressLine1": "628 Magnolia Boulevard",
564564
"ParticipantAddressLine2": "Penthouse",
565565
"ParticipantAddressLine3": "Financial District",
@@ -591,7 +591,7 @@
591591
"ExceptionDetails": {
592592
"GivenName": "Alexander",
593593
"FamilyName": "Rodriguez",
594-
"DateOfBirth": "19840711",
594+
"DateOfBirth": "1984-07-11",
595595
"ParticipantAddressLine1": "739 Dogwood Avenue",
596596
"ParticipantAddressLine2": "Studio 1",
597597
"ParticipantAddressLine3": "Arts Quarter",
@@ -623,7 +623,7 @@
623623
"ExceptionDetails": {
624624
"GivenName": "Harper",
625625
"FamilyName": "Lewis",
626-
"DateOfBirth": "19950302",
626+
"DateOfBirth": "1995-03-02",
627627
"ParticipantAddressLine1": "481 Redwood Circle",
628628
"ParticipantAddressLine2": "Flat 6B",
629629
"ParticipantAddressLine3": "University Area",
@@ -655,7 +655,7 @@
655655
"ExceptionDetails": {
656656
"GivenName": "Maya",
657657
"FamilyName": "Patel",
658-
"DateOfBirth": "19921103",
658+
"DateOfBirth": "1992-11-03",
659659
"ParticipantAddressLine1": "74 Riverbank Close",
660660
"ParticipantAddressLine2": "Flat 12",
661661
"ParticipantAddressLine3": "Kings Heath",
@@ -687,7 +687,7 @@
687687
"ExceptionDetails": {
688688
"GivenName": "Noah",
689689
"FamilyName": "Ahmed",
690-
"DateOfBirth": "19890921",
690+
"DateOfBirth": "1989-09-21",
691691
"ParticipantAddressLine1": "29 Hawthorn Close",
692692
"ParticipantAddressLine2": "House 3",
693693
"ParticipantAddressLine3": "Didsbury",
@@ -719,7 +719,7 @@
719719
"ExceptionDetails": {
720720
"GivenName": "Sarah",
721721
"FamilyName": "Green",
722-
"DateOfBirth": "19791223",
722+
"DateOfBirth": "1979-12-23",
723723
"ParticipantAddressLine1": "12 Meadow View",
724724
"ParticipantAddressLine2": "",
725725
"ParticipantAddressLine3": "",
@@ -751,7 +751,7 @@
751751
"ExceptionDetails": {
752752
"GivenName": "Grace",
753753
"FamilyName": "King",
754-
"DateOfBirth": "19860214",
754+
"DateOfBirth": "1986-02-14",
755755
"ParticipantAddressLine1": "14 Fern Close",
756756
"ParticipantAddressLine2": "",
757757
"ParticipantAddressLine3": "",
@@ -783,7 +783,7 @@
783783
"ExceptionDetails": {
784784
"GivenName": "Noah",
785785
"FamilyName": "Evans",
786-
"DateOfBirth": "19750203",
786+
"DateOfBirth": "1975-02-03",
787787
"ParticipantAddressLine1": "22 Brook Lane",
788788
"ParticipantAddressLine2": "",
789789
"ParticipantAddressLine3": "",
@@ -815,7 +815,7 @@
815815
"ExceptionDetails": {
816816
"GivenName": "Ava",
817817
"FamilyName": "Clark",
818-
"DateOfBirth": "19910421",
818+
"DateOfBirth": "1991-04-21",
819819
"ParticipantAddressLine1": "7 Orchard Way",
820820
"ParticipantAddressLine2": "",
821821
"ParticipantAddressLine3": "",
@@ -847,7 +847,7 @@
847847
"ExceptionDetails": {
848848
"GivenName": "Liam",
849849
"FamilyName": "Hall",
850-
"DateOfBirth": "19831130",
850+
"DateOfBirth": "1983-11-30",
851851
"ParticipantAddressLine1": "29 Heather Road",
852852
"ParticipantAddressLine2": "",
853853
"ParticipantAddressLine3": "",
@@ -879,7 +879,7 @@
879879
"ExceptionDetails": {
880880
"GivenName": "Maya",
881881
"FamilyName": "Ward",
882-
"DateOfBirth": "19970512",
882+
"DateOfBirth": "1997-05-12",
883883
"ParticipantAddressLine1": "63 Beech Avenue",
884884
"ParticipantAddressLine2": "",
885885
"ParticipantAddressLine3": "",

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: 6 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,15 @@ 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-
}
32-
33-
const date = new Date(`${year}-${month}-${day}`);
20+
const date = new Date(dateString);
3421
if (isNaN(date.getTime())) return "";
22+
3523
const options: Intl.DateTimeFormatOptions = {
36-
year: "numeric",
37-
month: "long",
3824
day: "numeric",
25+
month: "long",
26+
year: "numeric",
3927
};
28+
4029
return date.toLocaleDateString("en-GB", options);
4130
};
4231

0 commit comments

Comments
 (0)