-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.ts
45 lines (40 loc) · 972 Bytes
/
util.ts
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
45
/**
* Returns given date in "DD MMMM" format. Eg. "01 April".
*/
export function getDateString(date: Date): string {
const datePart = getDoubleDigitDate(date.getDate());
const monthPart = getMonthName(date.getMonth());
return `${datePart} ${monthPart}`;
}
/**
* Returns the double-digit representation of the given date.
* Eg. 1 becomes "01" but 21 stays "21".
*/
function getDoubleDigitDate(date: number): string {
let dateAsString = date.toString();
if (dateAsString.length < 2) {
dateAsString = `0${dateAsString}`;
}
return dateAsString;
}
/**
* Returns the English month name for the given 0-indexed month number.
* Eg. 3 becomes "April" and 11 becomes "December".
*/
function getMonthName(monNum: number): string {
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
return months[monNum];
}