-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.ts
More file actions
44 lines (40 loc) · 1.42 KB
/
utils.ts
File metadata and controls
44 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export const formatNhsNumber = (nhsNumber: string): string => {
return nhsNumber.replace(/(\d{3})(\d{3})(\d{4})/, "$1 $2 $3");
};
export const formatDate = (dateString: string): string => {
const date = new Date(dateString);
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "long",
day: "numeric",
};
return date.toLocaleDateString("en-GB", options);
};
export const formatCompactDate = (dateString: string): string => {
const year = dateString.slice(0, 4);
const month = dateString.slice(4, 6);
const day = dateString.slice(6, 8);
const date = new Date(`${year}-${month}-${day}`);
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "long",
day: "numeric",
};
return date.toLocaleDateString("en-GB", options);
};
export function getCurrentDate(): string {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
export function formatGenderValue(gender?: number | string | null): string {
if (gender === null || gender === undefined || gender === "")
return "Unknown";
const genderNum = typeof gender === "string" ? parseInt(gender, 10) : gender;
if (genderNum === 1) return "Male";
if (genderNum === 2) return "Female";
if (genderNum === 9) return "Unspecified";
return "Unknown";
}