mirror of
https://github.com/quantum5/qcal.git
synced 2025-04-24 17:51:57 -04:00
Create Gregorian to JDN conversion function
This commit is contained in:
parent
6393754f8f
commit
096858975b
18
src/Calendar.test.ts
Normal file
18
src/Calendar.test.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import {gregorianJDN} from "./Calendar";
|
||||
|
||||
describe('gregorianJDN', () => {
|
||||
it('works', () => {
|
||||
expect(gregorianJDN(2000, 1, 1)).toBe(2451545);
|
||||
expect(gregorianJDN(-4713, 11, 24)).toBe(0);
|
||||
expect(gregorianJDN(11917, 9, 18)).toBe(6073915);
|
||||
expect(gregorianJDN(-28565, 6, 17)).toBe(-8711925);
|
||||
expect(gregorianJDN(-26650, 4, 13)).toBe(-8012550);
|
||||
expect(gregorianJDN(17430, 3, 8)).toBe(8087303);
|
||||
expect(gregorianJDN(3395, 7, 18)).toBe(2961257);
|
||||
expect(gregorianJDN(4579, 3, 11)).toBe(3393575);
|
||||
expect(gregorianJDN(-14851, 11, 22)).toBe(-3702831);
|
||||
expect(gregorianJDN(8824, 11, 28)).toBe(4944292);
|
||||
expect(gregorianJDN(19720, 8, 14)).toBe(8923868);
|
||||
expect(gregorianJDN(7504, 7, 22)).toBe(4462042);
|
||||
});
|
||||
});
|
8
src/Calendar.ts
Normal file
8
src/Calendar.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
export function gregorianJDN(year: number, month: number, day: number) {
|
||||
const g = year + 4716 - (month <= 2 ? 1 : 0);
|
||||
const f = (month + 9) % 12;
|
||||
const e = Math.floor(1461 * g / 4) + day - 1402;
|
||||
const J = e + Math.floor((153 * f + 2) / 5);
|
||||
const dg = 38 - Math.floor(Math.floor((g + 184) / 100) * 3 / 4);
|
||||
return J + dg;
|
||||
}
|
Loading…
Reference in a new issue