September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,72 +1,118 @@
|
|||
/**
|
||||
* All Hail Discordia! - this script prints Discordian date using system date.
|
||||
* author: jklu, lang: JavaScript
|
||||
*
|
||||
* lang: JavaScript
|
||||
* author: jklu
|
||||
* contributors: JamesMcGuigan
|
||||
*
|
||||
* changelog:
|
||||
* - Modified to return same output syntax as unix ddate + module.exports - James McGuigan, 2/Chaos/3183
|
||||
*
|
||||
* source: https://rosettacode.org/wiki/Discordian_date#JavaScript
|
||||
*/
|
||||
var seasons = ["Chaos", "Discord", "Confusion",
|
||||
"Bureaucracy", "The Aftermath"];
|
||||
var weekday = ["Sweetmorn", "Boomtime", "Pungenday",
|
||||
"Prickle-Prickle", "Setting Orange"];
|
||||
var seasons = [
|
||||
"Chaos", "Discord", "Confusion",
|
||||
"Bureaucracy", "The Aftermath"
|
||||
];
|
||||
var weekday = [
|
||||
"Sweetmorn", "Boomtime", "Pungenday",
|
||||
"Prickle-Prickle", "Setting Orange"
|
||||
];
|
||||
|
||||
var apostle = ["Mungday", "Mojoday", "Syaday",
|
||||
"Zaraday", "Maladay"];
|
||||
var apostle = [
|
||||
"Mungday", "Mojoday", "Syaday",
|
||||
"Zaraday", "Maladay"
|
||||
];
|
||||
|
||||
var holiday = ["Chaoflux", "Discoflux", "Confuflux",
|
||||
"Bureflux", "Afflux"];
|
||||
var holiday = [
|
||||
"Chaoflux", "Discoflux", "Confuflux",
|
||||
"Bureflux", "Afflux"
|
||||
];
|
||||
|
||||
|
||||
Date.prototype.isLeapYear = function() {
|
||||
var year = this.getFullYear();
|
||||
if ((year & 3) !== 0) return false;
|
||||
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 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++;
|
||||
if( mn > 1 && this.isLeapYear() ) { dayOfYear++; }
|
||||
return dayOfYear;
|
||||
};
|
||||
|
||||
function discordianDate(date) {
|
||||
var y = date.getFullYear();
|
||||
var yold = y + 1166;
|
||||
var dayOfYear = date.getDOY();
|
||||
Date.prototype.isToday = function() {
|
||||
var today = new Date();
|
||||
return this.getDate() === today.getDate()
|
||||
&& this.getMonth() === today.getMonth()
|
||||
&& this.getFullYear() === today.getFullYear()
|
||||
;
|
||||
};
|
||||
|
||||
if (date.isLeapYear()) {
|
||||
if (dayOfYear == 60)
|
||||
return "St. Tib's Day, in the YOLD " + yold;
|
||||
else if (dayOfYear > 60)
|
||||
function discordianDate(date) {
|
||||
if( !date ) { date = new Date(); }
|
||||
|
||||
var y = date.getFullYear();
|
||||
var yold = y + 1166;
|
||||
var dayOfYear = date.getDOY();
|
||||
var celebrateHoliday = null;
|
||||
|
||||
if( date.isLeapYear() ) {
|
||||
if( dayOfYear == 60 ) {
|
||||
celebrateHoliday = "St. Tib's Day";
|
||||
}
|
||||
else if( dayOfYear > 60 ) {
|
||||
dayOfYear--;
|
||||
}
|
||||
}
|
||||
dayOfYear--;
|
||||
|
||||
var divDay= Math.floor(dayOfYear/73);
|
||||
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;
|
||||
if( seasonDay == 5 ) {
|
||||
celebrateHoliday = apostle[divDay];
|
||||
}
|
||||
if( seasonDay == 50 ) {
|
||||
celebrateHoliday = holiday[divDay];
|
||||
}
|
||||
|
||||
var season = seasons[divDay];
|
||||
var season = seasons[divDay];
|
||||
var dayOfWeek = weekday[dayOfYear % 5];
|
||||
|
||||
return dayOfWeek + ", day " + seasonDay + " of " +
|
||||
season + " in the YOLD " + yold;
|
||||
var nth = (seasonDay % 10 == 1) ? 'st'
|
||||
: (seasonDay % 10 == 2) ? 'nd'
|
||||
: (seasonDay % 10 == 3) ? 'rd'
|
||||
: 'th';
|
||||
|
||||
return "" //(date.isToday() ? "Today is " : '')
|
||||
+ dayOfWeek
|
||||
+ ", the " + seasonDay + nth
|
||||
+ " day of " + season
|
||||
+ " in the YOLD " + yold
|
||||
+ (celebrateHoliday ? ". Celebrate " + celebrateHoliday + "!" : '')
|
||||
;
|
||||
}
|
||||
|
||||
function test(y, m, d, result) {
|
||||
console.assert((discordianDate(new Date(y, m, d)) == result), result);
|
||||
console.assert((discordianDate(new Date(y, m, d)) == result), [y, m, d, discordianDate(new Date(y, m, d)), 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");
|
||||
// Only run test code if node calls this file directly
|
||||
if( require.main === module ) {
|
||||
console.log(discordianDate(new Date(Date.now())));
|
||||
test(2010, 6, 22, "Pungenday, the 57th day of Confusion in the YOLD 3176");
|
||||
test(2012, 1, 28, "Prickle-Prickle, the 59th day of Chaos in the YOLD 3178");
|
||||
test(2012, 1, 29, "Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib's Day!");
|
||||
test(2012, 2, 1, "Setting Orange, the 60th day of Chaos in the YOLD 3178");
|
||||
test(2010, 0, 5, "Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!");
|
||||
test(2011, 4, 3, "Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!");
|
||||
test(2015, 9, 19, "Boomtime, the 73rd day of Bureaucracy in the YOLD 3181");
|
||||
}
|
||||
|
||||
module.exports = discordianDate;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
console.log(discordianDate(new Date(Date.now())));
|
||||
"Prickle-Prickle, day 47 of The Aftermath in the YOLD 3181"
|
||||
"Boomtime, the 2nd day of Chaos in the YOLD 3183"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue