Skip to main content

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
JSR Score
100%
Published
3 weeks ago (1.0.0)

Converting Julian and Gregorian dates to each other.

This package assumes use of the Gregorian calendar and only works correctly for dates after 1858.

@ 2024 Hin Thar

@license http://www.apache.org/licenses/LICENSE-2.0

Checked with online converter of aavso, https://www.aavso.org/jd-calculator.


Install

npm i @hinthar/julian-days-converter
pnpm i @hinthar/julian-days-converter
yarn add @hinthar/julian-days-converter

CDN

jsd

<script src="https://cdn.jsdelivr.net/npm/@hinthar/julian-days-converter@1.0.0/dist/browser/index.min.js"></script>

UNPKG

<script src="https://www.unpkg.com/@hinthar/julian-days-converter@1.0.0/dist/browser/index.js"></script>

Usage

CJS

const julianDay = require("@hinthar/julian-days-converter");
const converter = julianDay();
// Gregorian to Julian
const jd = converter.toJD(2024, 4, 30);
// Julian to Gregorian
const gregorianDate = converter.toGregorian(2460430.5);
console.log(jd); // 2460430.5
console.log(gregorianDate);
// { year: 2024, month: 4, day: 30, hour: 12, minute: 0, second: 0 }

ESM

import julianDay from "@hinthar/julian-days-converter";
const converter = julianDay();
// Gregorian to Julian
const jd = converter.toJD(2024, 4, 30);
// Julian to Gregorian
const gregorianDate = converter.toGregorian(2460430.5);
console.log(jd); // 2460430.5
console.log(gregorianDate);
// { year: 2024, month: 4, day: 30, hour: 12, minute: 0, second: 0 }

Browser

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/@hinthar/julian-days-converter@1.0.0/dist/browser/index.min.js"></script>
  </head>
  <body>
    <script>
      // Gregorian to Julian
      var jd = toJD(2024, 4, 30);
      // Julian to Gregorian
      var gregorianDate = toGregorian(2460430.5);
      console.log(jd); // 2460430.5
      console.log(gregorianDate);
      // { year: 2024, month: 4, day: 30, hour: 12, minute: 0, second: 0 }
    </script>
  </body>
</html>

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @hinthar/julian-days-converter

Import symbol

import * as mod from "@hinthar/julian-days-converter";

Add Package

npx jsr add @hinthar/julian-days-converter

Import symbol

import * as mod from "@hinthar/julian-days-converter";

Add Package

yarn dlx jsr add @hinthar/julian-days-converter

Import symbol

import * as mod from "@hinthar/julian-days-converter";

Add Package

pnpm dlx jsr add @hinthar/julian-days-converter

Import symbol

import * as mod from "@hinthar/julian-days-converter";

Add Package

bunx jsr add @hinthar/julian-days-converter

Import symbol

import * as mod from "@hinthar/julian-days-converter";