Discordian date: Difference between revisions

→‎{{header|JavaScript}}: Modified to return same output syntax as unix ddate + module.exports - James McGuigan, 2/Chaos/3183
(→‎{{header|JavaScript}}: Modified to return same output syntax as unix ddate + module.exports - James McGuigan, 2/Chaos/3183)
Line 1,570:
/**
* All Hail Discordia! - this script prints Discordian date using system date.
*
* author: jklu, 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",
"Chaos", "Discord", "Confusion",
"Bureaucracy", "The Aftermath"];
var weekday = ["Sweetmorn", "Boomtime", "Pungenday",
];
"Prickle-Prickle", "Setting Orange"];
var weekday = [
var weekday = ["Sweetmorn", "Boomtime", "Pungenday",
"Prickle-Prickle", "Setting Orange"];
];
 
var apostle = ["Mungday", "Mojoday", "Syaday",
"ZaradayMungday", "MaladayMojoday"];, "Syaday",
"Zaraday", "Maladay"
];
 
var holiday = ["Chaoflux", "Discoflux", "Confuflux",
"BurefluxChaoflux", "AffluxDiscoflux"];, "Confuflux",
"Bureflux", "Afflux"
];
 
 
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
if ( (year & 3) !== 0 ) { return false; }
return ((year % 100) !== 0 || (year % 400) === 0);
};
Line 1,592 ⟶ 1,608:
// 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;
};
 
Date.prototype.isToday = function() {
var yoldtoday = ynew + 1166Date();
return this.getDate() === today.getDate()
&& this.getMonth() === today.getMonth()
&& this.getFullYear() === today.getFullYear()
;
};
 
function discordianDate(date) {
varif( y!date =) { date.getFullYear = new Date(); }
var yold = y + 1166;
var dayOfYear = date.getDOY();
 
ifvar y = (date.isLeapYeargetFullYear()) {;
var yold = y + 1166;
if (dayOfYear == 60)
var dayOfYear return "St. Tib's Day, in the= YOLD " + yolddate.getDOY();
var celebrateHoliday = null;
else if (dayOfYear > 60)
 
if( date.isLeapYear() ) {
var if( dayOfYear == date.getDOY(60 ); {
celebrateHoliday = "St. Tib's Day";
}
ifelse if( dayOfYear ==> 60 ) {
dayOfYear--;
}
}
dayOfYear--;
 
var divDay = Math.floor(dayOfYear / 73);
 
var seasonDay = (dayOfYear % 73) + 1;
if ( seasonDay == 5 ) {
returncelebrateHoliday = apostle[divDay] + ", in the YOLD " + yold;
}
if ( seasonDay == 50 ) {
return holiday[divDay] + ", in the YOLD " + yold;
celebrateHoliday = holiday[divDay];
}
 
var season = seasons[divDay];
var dayOfWeek = weekday[dayOfYear % 5];
 
var nth = (seasonDay % 10 == 1) ? 'st'
return dayOfWeek + ", day " + seasonDay + " of " +
season + " in the YOLD ": +(seasonDay yold;% 10 == 2) ? 'nd'
: (seasonDay % 10 == 3) ? 'rd'
: 'th';
 
return "" //(date.isToday() ? "Today is " : '')
+ dayOfWeek
return dayOfWeek + ", daythe " + seasonDay + " of " +nth
+ " day of " + season
return holiday[divDay] + ", in the YOLD " + yold;
+ (celebrateHoliday ? ". Celebrate " + celebrateHoliday + "!" : '')
;
}
 
function test(y, m, d, result) {
console.assert((discordianDate(new Date(y, m, d)) == result), [y, m, d, discordianDate(new Date(y, m, d)), result]);
}
 
// Only run test code if node calls this file directly
console.log(discordianDate(new Date(Date.now())));
if( require.main === module ) {
test(2010, 6, 22, "Pungenday, day 57 of Confusion in the YOLD 3176");
console.log(discordianDate(new Date(Date.now())));
test(2012, 1, 28, "Prickle-Prickle, day 59 of Chaos in the YOLD 3178");
test(20122010, 16, 2922, "St.Pungenday, Tib'sthe Day,57th day of Confusion in the YOLD 31783176");
test(2012, 21, 128, "Setting OrangePrickle-Prickle, daythe 6059th day of Chaos in the YOLD 3178");
test(20102012, 01, 529, "MungdaySetting Orange, the 60th day of Chaos in the YOLD 31763178. Celebrate St. Tib's Day!");
test(20112012, 42, 3 1, "DiscofluxSetting Orange, the 60th day of Chaos in the YOLD 31773178");
test(20152010, 90, 19 5, "BoomtimeSetting Orange, daythe 735th day of BureaucracyChaos in the YOLD 31813176. Celebrate Mungday!");</lang>
test(20102011, 64, 22 3, "Pungenday, daythe 5750th day of ConfusionDiscord in the YOLD 31763177. Celebrate Discoflux!");
test(20122015, 19, 2819, "Prickle-PrickleBoomtime, daythe 5973rd day of ChaosBureaucracy in the YOLD 31783181");
}
 
module.exports = discordianDate;
</lang>
 
Example use:
Line 1,645 ⟶ 1,692:
<lang javascript>
console.log(discordianDate(new Date(Date.now())));
"Prickle-PrickleBoomtime, daythe 472nd ofday Theof AftermathChaos in the YOLD 31813183"
</lang>