RA-#20 Update news badge

This commit is contained in:
ostertun
2020-10-02 01:23:46 +02:00
parent 2ea26408be
commit 856f6c1d66
4 changed files with 45 additions and 20 deletions

View File

@@ -27,13 +27,13 @@ function parseDate(string) {
} else {
return null;
}
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
if (year.toString().length == 2) year = (year < 70 ? 2000 : 1900) + year;
if ((year < 1970) || (year > 3000)) return null;
if ((month < 1) || (month > 12)) return null;
if ((day < 1) || (day > 31)) return null;
var date = new Date(Date.UTC(year, month - 1, day));
return date;
}
@@ -51,37 +51,37 @@ function formatDate(format, date = null) {
date = new Date(date.valueOf());
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
}
format = format.replace("M", "%1%");
format = format.replace("F", "%2%");
format = format.replace("D", "%3%");
format = format.replace("l", "%4%");
var tmp = date.getFullYear().toString();
var tmp2 = tmp.substr(2);
format = format.replace("Y", tmp);
format = format.replace('y', tmp2);
tmp = (date.getMonth() + 1).toString();
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
format = format.replace('n', tmp);
format = format.replace('m', tmp2);
tmp = date.getDate().toString();
tmp2 = (tmp.length > 1 ? tmp : ('0' + tmp));
format = format.replace('j', tmp);
format = format.replace('d', tmp2);
tmp = date.getDay();
tmp2 = (tmp == 0 ? 7 : tmp);
format = format.replace('w', tmp);
format = format.replace('N', tmp2);
format = format.replace('%1%', strings.months_short[date.getMonth()]);
format = format.replace('%2%', strings.months_long[date.getMonth()]);
format = format.replace('%3%', strings.weekdays_short[date.getDay()]);
format = format.replace('%4%', strings.weekdays_long[date.getDay()]);
return format;
}