Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.62 KB

README.md

File metadata and controls

55 lines (41 loc) · 1.62 KB

Modern Julian Date

npm (scoped) DeepSource Code Climate maintainability codecov

Converts a regular JavaScript date to the modern Julian date format YYYYDDD, commonly seen in banking applications.

Getting Started

npm install @cityssm/modern-julian-date

Usage

import {
  fromModernJulianDate,
  toModernJulianDate,
  toShortModernJulianDate
} from "@cityssm/modern-julian-date";

/*
 * toModernJulianDate()
 * Returns date strings in YYYYDDD format.
 */

console.log( toModernJulianDate(new Date(2022, 1 - 1, 1)) );
// => '2022001'

console.log( toModernJulianDate(new Date(2022, 12 - 1, 31)) );
// => '2022365'

console.log( toModernJulianDate(new Date(2020, 12 - 1, 31)) );
// => '2020366'

/*
 * toShortModernJulianDate()
 * Returns date strings in YYDDD format.
 */

console.log( toShortModernJulianDate(new Date(2022, 1 - 1, 1)) );
// => '22001'

/*
 * fromModernJulianDate()
 * Returns Date objects.
 */

console.log( fromModernJulianDate('2020366') )
// => 'Thu Dec 31 2020 00:00:00 GMT-0500 (Eastern Standard Time)'