Converts a regular JavaScript date to the modern Julian date format YYYYDDD, commonly seen in banking applications.
npm install @cityssm/modern-julian-date
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)'