-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenreader-dates.js
38 lines (31 loc) · 1.42 KB
/
screenreader-dates.js
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
var elements = document.querySelectorAll('time[datetime]');
elements.forEach(function (element) {
applyLabel(element);
});
function applyLabel(element){
var datetime = new Date(element.getAttribute('datetime')),
year = datetime.getFullYear(),
month = datetime.getMonth(),
day = datetime.getDate(),
weekday = datetime.getDay(),
readableMonth,
readableDay,
readableWeekday;
console.log(datetime);
convertMonth(month);
convertDay(day);
convertWeekday(weekday);
element.setAttribute('aria-label', readableWeekday + ', ' + readableMonth + ' ' + readableDay + ', ' + year + '.');
function convertMonth(m){
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
readableMonth = months[m];
}
function convertDay(d){
var days = ['Zero','First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eight', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth', 'Thirteenth', 'Fourteenth', 'Fifteenth', 'Sixteenth','Seventeenth','Eighteenth','Nineteenth','Twentieth','Twenty-first','Twenty-second','Twenty-third','Twenty-fourth','Twenty-fifth','Twenty-sixth','Twenty-seventh','Twenty-eight','Twenty-ninth','Thirtieth','Thirty-first'];
readableDay = days[d];
}
function convertWeekday(w){
var weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
readableWeekday = weekdays[w];
}
}