Julian & Republican dates
by toubia95
CSS
/*cf http://calendarhome.com/calculate/convert-a-date/ */
/*
* GREG => JULIAN [OK]
* GREG => REPUBLICAIN [OK]
* GREG => HEBRAIQUE [OK mais on utilisera pas tout de suite]
* REP => GREG [EN ATTENTE]
*/
JavaScript
/* ===============
JULIAN CALENDAR
=============== */
// GREGORIAN_TO_JD -- Determine Julian day number from Gregorian calendar date
var GREGORIAN_EPOCH = 1721425.5;
// LEAP_GREGORIAN -- Is a given year in the Gregorian calendar a leap year ?
function leap_gregorian(year) {
return ((year % 4) === 0) && (!(((year % 100) === 0) && ((year % 400) !== 0)));
}
function gregorian_to_jd(year, month, day) {
return (GREGORIAN_EPOCH - 1) + (365 * (year - 1)) + Math.floor((year - 1) / 4) + (-Math.floor((year - 1) / 100)) + Math.floor((year - 1) / 400) + Math.floor((((367 * month) - 362) / 12) + ((month <= 2) ? 0 : (leap_gregorian(year) ? -1 : -2)) + day);
}
// JD_TO_JULIAN -- Calculate Julian calendar date from Julian day
function jd_to_julian(td) {
var z, a, b, c, d, e, year, month, day;
td += 0.5;
z = Math.floor(td);
a = z;
b = a + 1524;
c = Math.floor((b - 122.1) / 365.25);
d = Math.floor(365.25 * c);
e = Math.floor((b - d) / 30.6001);
month = Math.floor((e < 14) ? (e - 1) : (e - 13));
year = Math.floor((month > 2) ? (c - 4716) : (c - 4715));
day = b - d - Math.floor(30.6001 * e);
/* If year is less than 1, subtract one to convert from
a zero based date system to the common era system in
which the year -1 (1 B.C.E) is followed by year 1 (1 C.E.). */
if (year < 1) {
year -= 1; //year--;
}
return [year, month, day];
}
// JWDAY -- Calculate day of week from Julian day
var Weekdays = new Array("Dimanche", "Lundi", "Mardi", "Mercredi",
"Jeudi", "Vendredi", "Samedi");
function jwday(j) {
return mod(Math.floor((j + 1.5)), 7);
}
/* MOD -- Modulus function which works for non-integers. */
function mod(a, b) {
return a - (b * Math.floor(a / b));
}
/* =============================
FRENCH REVOLUTIONARY CALENDAR
============================= */
/* JD_TO_FRENCH_REVOLUTIONARY -- Calculate date in the French Revolutionary
calendar from...