P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Date
:
Date.getRomanDate()
author:
LennyNero
[+]
,
Submitted: 08.23.05 7a
• Last Edit: 07.04.08 12p
// Author: Cosimo Manfredonia // www.cosimomanfredonia.it Date.prototype.getRomanDate = function() { var monthDays = new Date(this.getFullYear(), this.getMonth()+1, 0).getDate(); var date = this.getDate(); var month = this.getMonth(); var dayBefore = "pridie"; var nDayBefore = "a. d."; // or "ante diem" var strYear = " Anno Domini "+arabToRoman(this.getFullYear()); var nonae; var idus; if (month == 2 || month == 4 || month == 6 || month == 9) { nonae = 7; idus = 15; } else { nonae = 5; idus = 13; } if (monthDays == 29) { // Trivia // Why do we call "bissextile" an year that has 366 days? // A new day was inserted between 23rd end 24th Feb // 24th Feb was the sixth day before March kalends 'dies sextus ante Kalendas Martias' // the inserted day was called 'dies "bis sextus" ante Kalendas Martias' if (date == 24) { return nDayBefore+" bis VI Kalendas Martias"+strYear; } else if (date>24) { date--; } monthDays = 28; } if (date == 1) { return "Kalendis "+latinMonth(month, "g")+strYear; } else if (date<nonae-1) { return nDayBefore+" "+arabToRoman(nonae-date+1)+" Nonas "+latinMonth(month)+strYear; } else if (date == nonae-1) { return dayBefore+" Nonas "+latinMonth(month)+strYear; } else if (date == nonae) { return "Nonis "+latinMonth(month, "g")+strYear; } else if (date<idus-1) { return nDayBefore+" "+arabToRoman(idus-date+1)+" Idus "+latinMonth(month)+strYear; } else if (date == idus-1) { return dayBefore+" Idus "+latinMonth(month)+strYear; } else if (date == idus) { return "Idibus "+latinMonth(month, "g")+strYear; } else if (date<monthDays) { return nDayBefore+" "+arabToRoman(monthDays-date+2)+" Kalendas "+latinMonth((month<11) ? month+1 : 0)+strYear; } else if (date=monthDays) { return dayBefore+" Kalendas "+latinMonth((month<11) ? month+1 : 0)+strYear; } function latinMonth(month, theCase) { if (theCase == "g") { // genitive case var acc = false; } else { // accusative case - default value var acc = true; } switch (month) { case 0 : return acc ? "Ianuarias" : "Ianuariis"; case 1 : return acc ? "Februarias" : "Februariis"; case 2 : return acc ? "Martias" : "Martiis"; case 3 : return acc ? "Apriles" : "Aprilibus"; case 4 : return acc ? "Maias" : "Maiis"; case 5 : return acc ? "Iunias" : "Iuniis"; case 6 : return acc ? "Iulias" : "Iuliis"; case 7 : return acc ? "Augustas" : "Augustis"; case 8 : return acc ? "Septembres" : "Septembribus"; case 9 : return acc ? "Octobres" : "Octobribus"; case 10 : return acc ? "Novembres" : "Novembribus"; case 11 : return acc ? "Decembres" : "Decembribus"; } } function arabToRoman(num) { if (num>3999) { // this algorithm works if num <= 3999; return "????"; } else { var tho = Math.floor(num/1000); var hun = Math.floor((num-tho*1000)/100); var ten = Math.floor((num-tho*1000-hun*100)/10); var uni = Math.floor(num-tho*1000-hun*100-ten*10); return toRoman(tho, 3)+toRoman(hun, 2)+toRoman(ten, 1)+toRoman(uni, 0); } function toRoman(dig, pow) { var str = ''; var symbols = []; symbols[0] = ['I', 'V', 'X']; symbols[1] = ['X', 'L', 'C']; symbols[2] = ['C', 'D', 'M']; if (pow>2) { for (var i = 0; i<dig; i++) { str += 'M'; } return str; } else { switch (dig) { case 1 : str = symbols[pow][0]; break; case 2 : str = symbols[pow][0]+symbols[pow][0]; break; case 3 : str = symbols[pow][0]+symbols[pow][0]+symbols[pow][0]; break; case 4 : str = symbols[pow][0]+symbols[pow][1]; break; case 5 : str = symbols[pow][1]; break; case 6 : str = symbols[pow][1]+symbols[pow][0]; break; case 7 : str = symbols[pow][1]+symbols[pow][0]+symbols[pow][0]; break; case 8 : str = symbols[pow][1]+symbols[pow][0]+symbols[pow][0]+symbols[pow][0]; break; case 9 : str = symbols[pow][0]+symbols[pow][2]; break; } return str; } } } };
usage
//Example: today=new Date(); trace("today is -> "+today.getRomanDate()); day=new Date(2005, 1, 24); trace("24/02/2005 is -> "+day.getRomanDate()); day=new Date(2004, 1, 24); trace("...but"); trace("24/02/2004 is -> "+day.getRomanDate());
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@