mirror of
https://github.com/quantum5/qcal.git
synced 2025-04-24 17:51:57 -04:00
Create French to JDN conversion function
This commit is contained in:
parent
096858975b
commit
5e5f44c76d
|
@ -1,4 +1,4 @@
|
|||
import {gregorianJDN} from "./Calendar";
|
||||
import {frJDN, gregorianJDN} from './Calendar';
|
||||
|
||||
describe('gregorianJDN', () => {
|
||||
it('works', () => {
|
||||
|
@ -16,3 +16,16 @@ describe('gregorianJDN', () => {
|
|||
expect(gregorianJDN(7504, 7, 22)).toBe(4462042);
|
||||
});
|
||||
});
|
||||
|
||||
describe('frJDN', () => {
|
||||
it('works for sample dates', () => {
|
||||
expect(frJDN(1, 1, 1)).toBe(2375840);
|
||||
expect(frJDN(8, 2, 18)).toBe(2378444);
|
||||
});
|
||||
|
||||
it('works in years starting/ending near midnight', () => {
|
||||
expect(frJDN( 111, 1, 1)).toBe(2416017); // equinox 1902-09-23T23:55:19 UT1
|
||||
expect(frJDN( 206, 1, 1)).toBe(2450715); // equinox 1997-09-22T23:55:46 UT1
|
||||
expect(frJDN(2490, 1, 1)).toBe(3284926); // equinox 4281-09-20T23:50:38 UT1
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
import data from '../cal.json';
|
||||
|
||||
const startJD = data.start_jd;
|
||||
const startYear = data.start_year;
|
||||
const leaps: Array<number> = [0];
|
||||
|
||||
let leapFromStart = 0;
|
||||
data.leap.forEach(leap => {
|
||||
leapFromStart += leap;
|
||||
leaps.push(leapFromStart);
|
||||
});
|
||||
|
||||
export function gregorianJDN(year: number, month: number, day: number) {
|
||||
const g = year + 4716 - (month <= 2 ? 1 : 0);
|
||||
const f = (month + 9) % 12;
|
||||
|
@ -6,3 +18,9 @@ export function gregorianJDN(year: number, month: number, day: number) {
|
|||
const dg = 38 - Math.floor(Math.floor((g + 184) / 100) * 3 / 4);
|
||||
return J + dg;
|
||||
}
|
||||
|
||||
export function frJDN(year: number, month: number, day: number) {
|
||||
const dy = year - startYear;
|
||||
const dd = month * 30 + day - 31;
|
||||
return startJD + 365 * dy + leaps[dy] + dd;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue