2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,49 +1,72 @@
/**
* All Hail Discordia! - this script prints Discordian date using system date.
* author: s1w_, lang: JavaScript
* author: jklu, lang: JavaScript
*/
function print_ddate(mod) {
var p;
switch(mod || 0) {// <--choose display pattern or pass option by parameter
default:
case 0:/* Sweetmorn, Day 57 of the Season of Confusion, Anno Mung 3177 */ p="{0}, [Day {1} of the Season of {2}], Anno Mung {3}"; break;
case 1:/* Sweetmorn, The 57th Day of Confusion, 3177 YOLD */ p="{0}, [The {1}th Day of {2}], {3} YOLD"; break;
case 2:/* Sweetmorn, the 57th day of Confusion, AM 3177 */ p="{0}, [the {1}th day of {2}], AM {3}"; break;
case 3:/* Sweetmorn / Confusion 57th / AM 3177 */ p="{0} / [{2} {1}th] / AM {3}"; break;
}
var ddateStr, curr, sum, extra, today, day, month, year, dSeason, dDay, season, ddate, dyear;
var seasons = ["Chaos", "Discord", "Confusion",
"Bureaucracy", "The Aftermath"];
var weekday = ["Sweetmorn", "Boomtime", "Pungenday",
"Prickle-Prickle", "Setting Orange"];
format = function(s, $1, $2, $3, $4) {
if ($2 != undefined) {
var postfix;
switch(parseInt($2.charAt($2.length-1))) {
case 1: postfix = '}st'; break;
case 2: postfix = '}nd'; break;
case 3: postfix = '}rd'; break;
default:postfix = '}th';
}
return p.replace(/\}th/, postfix).replace(/(\[|\])/g, '').format($1, $2, $3, $4);
}
else return p.replace(/\[.*?\]/,"<span style='color:green'>{2}</span>").format($1, $2, $3, $4);
}
var apostle = ["Mungday", "Mojoday", "Syaday",
"Zaraday", "Maladay"];
String.prototype.format = function() {
var pattern = /\{\d+\}/g;
var args = arguments;
return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
}
var holiday = ["Chaoflux", "Discoflux", "Confuflux",
"Bureflux", "Afflux"];
dDay = new Array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
dSeason = new Array("Chaos", "Discord", "Confusion", "Bureaucracy", "Aftermath");
curr = new Date(); extra = new Array(0,3,0,3,2,3,2,3,3,2,3,2);
today = curr.getDate(); month = curr.getMonth(); year = curr.getFullYear();
sum = month * 28;
for(var i=0; i<=month; i++)
sum += extra[i];
sum += today;
day = (sum - 1) % 5; ddate = sum % 73;
season = (month==1)&&(today==29) ? "St. Tib\'s Day" : dSeason[Math.floor(sum/73)];
dyear = year+1166;
ddateStr = ""+dDay[day]+ddate+season+dyear;
document.write(ddateStr.replace(/(\D+)(?:(\d+)(?!St)|(?:\d+))(\D+)(\d+)/i, format));
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
if ((year & 3) !== 0) return false;
return ((year % 100) !== 0 || (year % 400) === 0);
};
// Get Day of Year
Date.prototype.getDOY = function() {
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
var mn = this.getMonth();
var dn = this.getDate();
var dayOfYear = dayCount[mn] + dn;
if (mn > 1 && this.isLeapYear()) dayOfYear++;
return dayOfYear;
};
function discordianDate(date) {
var y = date.getFullYear();
var yold = y + 1166;
var dayOfYear = date.getDOY();
if (date.isLeapYear()) {
if (dayOfYear == 60)
return "St. Tib's Day, in the YOLD " + yold;
else if (dayOfYear > 60)
dayOfYear--;
}
dayOfYear--;
var divDay= Math.floor(dayOfYear/73);
var seasonDay = (dayOfYear % 73) + 1;
if (seasonDay == 5)
return apostle[divDay] + ", in the YOLD " + yold;
if (seasonDay == 50)
return holiday[divDay] + ", in the YOLD " + yold;
var season = seasons[divDay];
var dayOfWeek = weekday[dayOfYear % 5];
return dayOfWeek + ", day " + seasonDay + " of " +
season + " in the YOLD " + yold;
}
function test(y, m, d, result) {
console.assert((discordianDate(new Date(y, m, d)) == result), result);
}
console.log(discordianDate(new Date(Date.now())));
test(2010, 6, 22, "Pungenday, day 57 of Confusion in the YOLD 3176");
test(2012, 1, 28, "Prickle-Prickle, day 59 of Chaos in the YOLD 3178");
test(2012, 1, 29, "St. Tib's Day, in the YOLD 3178");
test(2012, 2, 1, "Setting Orange, day 60 of Chaos in the YOLD 3178");
test(2010, 0, 5, "Mungday, in the YOLD 3176");
test(2011, 4, 3, "Discoflux, in the YOLD 3177");
test(2015, 9, 19, "Boomtime, day 73 of Bureaucracy in the YOLD 3181");

View file

@ -1,8 +1,2 @@
print_ddate()
"Sweetmorn, Day 57 of the Season of Confusion, Anno Mung 3177"
print_ddate(1)
"Sweetmorn, The 57th Day of Confusion, 3177 YOLD"
print_ddate(2)
"Sweetmorn, the 57th day of Confusion, AM 3177"
print_ddate(3)
"Sweetmorn / Confusion 57th / AM 3177"
console.log(discordianDate(new Date(Date.now())));
"Prickle-Prickle, day 47 of The Aftermath in the YOLD 3181"