Skip to content

Latest commit

 

History

History
127 lines (93 loc) · 2.76 KB

README.md

File metadata and controls

127 lines (93 loc) · 2.76 KB

Converting Julian and Gregorian dates to each other.

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


Install from jsr.io

JSR Scope JSR JSR Score

npm

npx jsr add @hinthar/julian-days-converter

yarn

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

pnpm

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

deno

deno add @hinthar/julian-days-converter

bun

bunx jsr add @hinthar/julian-days-converter

Install from npm registry

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

From CDN

jsd

<script src="https://cdn.jsdelivr.net/npm/@hinthar/[email protected]/dist/browser/index.min.js"></script>

UNPKG

<script src="https://www.unpkg.com/@hinthar/[email protected]/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/[email protected]/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>