/calendrical

Fourmilab Calendar Converter as a library

Primary LanguageJavaScript

Note:

This library is a more or less direct port of the Fourmilab Calendar Converter, just extracted from the DOM.

Testing

A crude test suite is in place, consisting of basic jasmine test cases for the astro package and the Bahai calendar.

Currently it is not suitable for production usage. YMMV.

To run the test suite, you need node.js, npm and bower installed. Then type the following:

bower install
npm install

Open the page test/index.html in your favourite web browser.

Calendrical

Fourmilab Calendar Converter as a library.

Demo
Annotated

Usage

now = new Date();
// => Mon Jun 24 2013 17:24:03 GMT-0400 (EDT)

Calendrical.calendar.updateTo(now);
// => Object {weekdayBefore: function, searchWeekday: function, nearestWeekday: function, nextWeekday: function, nextOrCurrentWeekday: function…}

console.log(Calendrical.data);
// => Object {bahai: Object, excel_serial_1900: Object, excel_serial_1904: Object, french: Object, gregorian: Object…}
now = new Date();
// => Mon Jun 24 2013 17:24:03 GMT-0400 (EDT)

now.getBahai();
// => Object {kull_i_shay: 1, vahid: 9, year: "Abhá", month: "Rahmat", day: "Jalál"…}

now.getExcel1904();
// => Object {day: 39987.72503472213}

now.getMayan();
// => Object {baktun: 13, katun: 0, tun: 0, uinal: 9, kin: 6…}

Calendrical.astro.equationOfTime(now.getJulian());
// => 0.013450386503067681

Calendrical.astro.sunpos(now.getJulian());
// => [93.03022447720286, 169.86108842444628, 0.016702965507475936, 0.33014519687687366, 93.36036967407973, 170.19123362132316, 1.0164516012170814, 93.35802029179253, 93.66176291046486, 23.394838008347406, 93.65915335631958, 23.39307037447384]