Posted By

s1w on 06/18/11


Tagged

date discordian eris ddate hail discordia


Versions (?)

Discordian Date >> JavaScript


 / Published in: JavaScript
 

  1. /**
  2.  * All Hail Discordia! - this script prints Discordian date using system date.
  3.  * author: s1w_, lang: JavaScript
  4.  */
  5. function print_ddate(mod) {
  6. var p;
  7. switch(mod || 0) {// <--choose display pattern or pass option by parameter
  8. default:
  9. 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;
  10. case 1:/* Sweetmorn, The 57th Day of Confusion, 3177 YOLD */ p="{0}, [The {1}th Day of {2}], {3} YOLD"; break;
  11. case 2:/* Sweetmorn, the 57th day of Confusion, AM 3177 */ p="{0}, [the {1}th day of {2}], AM {3}"; break;
  12. case 3:/* Sweetmorn / Confusion 57th / AM 3177 */ p="{0} / [{2} {1}th] / AM {3}"; break;
  13. }
  14. var ddateStr, curr, sum, extra, today, day, month, year, dSeason, dDay, season, ddate, dyear;
  15.  
  16. format = function(s, $1, $2, $3, $4) {
  17. if ($2 != undefined) {
  18. var postfix;
  19. switch(parseInt($2.charAt($2.length-1))) {
  20. case 1: postfix = '}st'; break;
  21. case 2: postfix = '}nd'; break;
  22. case 3: postfix = '}rd'; break;
  23. default:postfix = '}th';
  24. }
  25. return p.replace(/\}th/, postfix).replace(/(\[|\])/g, '').format($1, $2, $3, $4);
  26. }
  27. else return p.replace(/\[.*?\]/,"<span style='color:green'>{2}</span>").format($1, $2, $3, $4);
  28. }
  29.  
  30. String.prototype.format = function() {
  31. var pattern = /\{\d+\}/g;
  32. var args = arguments;
  33. return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
  34. }
  35.  
  36. dDay = new Array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
  37. dSeason = new Array("Chaos", "Discord", "Confusion", "Bureaucracy", "Aftermath");
  38. curr = new Date(); extra = new Array(0,3,0,3,2,3,2,3,3,2,3,2);
  39. today = curr.getDate(); month = curr.getMonth(); year = curr.getFullYear();
  40. sum = month * 28;
  41. for(var i=0; i<=month; i++)
  42. sum += extra[i];
  43. sum += today;
  44. day = (sum - 1) % 5; ddate = sum % 73;
  45. season = (month==1)&&(today==29) ? "St. Tib\'s Day" : dSeason[Math.floor(sum/73)];
  46. dyear = year+1166;
  47. ddateStr = ""+dDay[day]+ddate+season+dyear;
  48. document.write(ddateStr.replace(/(\D+)(?:(\d+)(?!St)|(?:\d+))(\D+)(\d+)/i, format));
  49. }

Report this snippet  

You need to login to post a comment.