gdate-julian

Converts date to and from julian days in gLib GDate style

Usage no npm install needed!

<script type="module">
  import gdateJulian from 'https://cdn.skypack.dev/gdate-julian';
</script>

README

GDate (GLib) style julian days to and from gregorian date converter

Port of GLib functions to work with julian days, to convert between it and gregorian date. Library was initially developed to help a sister library node-xhb work with file generated by HomeBank

Install

npm install gdate-julian

Usage

Import ESM style

import {g_date_to_julian_days, g_julian_days_to_date} from 'gdate-julian' 

or CJS Style

const {g_date_to_julian_days, g_julian_days_to_date} = require('gdate-julian')

each method is also exported as camelCase alias:

import {gDate2JulianDays, gJulianDays2Date} from 'gdate-julian' 

or CJS Style

const {gDate2JulianDays, gJulianDays2Date} = require('gdate-julian')

Example

Here we show small example how to convert between Gregorian Date and Julian Days More detailed examples can be found in tests in ./src/__tests__/g_date_conversion_spec.js

Gregorian Date to Julian Days

const julianDays = gDate2JulianDays(new Date('1900-01-01T12:00:00Z'))
console.log(julianDays) // outputs 693596

Julian Days to Gregorian Date

const gregorianDate = gJulianDays2Date(693596)
console.log(gregorianDate) // outputs 1900-01-01T12:00:00Z

TypeScript definitions

Project also includes type definitions for TypeScript in ./src/index.d.ts

export type g_date_is_leap_year = (year: number) => boolean;
export type g_julian_days_to_date = (julian_days: number) => Date;
export type g_date_to_julian_days = (date: Date) => number;

License

The code provided here is based off GLib codebase, hence licenced under same LGPL.