Repository navigation
Expand file tree
/
Copy pathdate.js
More file actions
127 lines (117 loc) · 3.77 KB
/
Copy pathdate.js
File metadata and controls
127 lines (117 loc) · 3.77 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
console.log(dateToLatinDate(new Date("2022-12-05")))
function dateToLatinDate(date) {
let day = date.getDate();
let idus = getIdus(date.getMonth());
let nonae = getNonae(idus);
let lastDayOfMonth = getLastDayOfMonth(date.getMonth(), date.getFullYear());
if (day === idus) {
return getDateText("Idibus", 0, date);
} else if (day === idus - 1) {
return getDateText("Idus", 1, date)
} else if (day === 1) {
return getDateText("Kalendis", 0, date)
} else if (day < idus) {
if (day > nonae) {
return getDateText("Idus", calcDaysBeforeEvent(idus, day), date)
} else if (day === nonae) {
return getDateText("Nonis", 0, date)
} else if (day === nonae - 1) {
return getDateText("Nonas", 1, date)
} else {
return getDateText("Nonas", calcDaysBeforeEvent(nonae, day), date)
}
} else if (day === lastDayOfMonth) {
return getDateText("Kalendas", 1, date)
} else {
return getDateText("Kalendas", calcDaysBeforeEvent(lastDayOfMonth + 1, day), date)
}
}
function getIdus(month) {
month = month + 1 // JS is counting months from 0
switch (month) {
case 3: // March
case 7: // July
case 5: // May
case 10: // October
return 15;
default: // The other months
return 13;
}
}
function getNonae(idus) {
return idus - 8;
}
function getLastDayOfMonth(month, year) {
const d = new Date(year, month + 1, 0);
return d.getDate()
}
function calcDaysBeforeEvent(eventDate, calcDate) {
return (eventDate - calcDate + 1)
}
function getDateText(event, daysBeforeEvent, currentDate) {
let month = currentDate.getMonth()
if (event.startsWith("Kalend") && (daysBeforeEvent !== 0)) {
if (month === 11) month = -1;
month = month + 1;
}
if (daysBeforeEvent === 0) {
return event + " " + monthToLatin(month, true)
} else if (daysBeforeEvent === 1) {
return "Pridie " + event + " " + monthToLatin(month)
}
return "ante diem " + intToLatinTxtAkk(daysBeforeEvent) + " " + event + " " + monthToLatin(month)
}
function getLatinMonths(inAbl) {
if (inAbl) {
return ["Ianuariis", "Februariis", "Martiis", "Aprilibus", "Maiis", "Iuniis", "Iuliis", "Sextilibus",
"Septembribus", "Octobribus", "Novembribus", "Decembribus"]
}
return ["Ianuarias", "Februarias", "Martias", "Apriles", "Maias", "Iunias", "Iulias", "Sextiles",
"Septembres", "Octobres", "Novembres", "Decembres"]
}
function monthToLatin(month, inAbl=false) {
return getLatinMonths(inAbl)[month]
}
function intToLatinTxtAkk(int) {
let latNumber = "";
if (int >= 10 && int < 20 && int !== 11 && int !== 12) {
latNumber += "decimum ";
int = int - 10;
}
console.log(int)
switch (Number(int)) {
case 1:
latNumber += "unum";
break; // Will not be used
case 2:
latNumber += "secundum";
break;
case 3:
latNumber += "tertium";
break;
case 4:
latNumber += "quartum";
break;
case 5:
latNumber += "quintum";
break;
case 6:
latNumber += "sextum";
break;
case 7:
latNumber += "septimum";
break;
case 8:
latNumber += "octavum";
break;
case 9:
latNumber += "novum";
break;
case 11:
latNumber += "undecimum";
break;
case 12:
latNumber += "duodecimum";
}
return latNumber.trim()
}