gdate-julian
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "gdate-julian", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Converts date to and from julian days in gLib GDate style", | ||
"main": "src/index.js", | ||
"main": "./src/index.js", | ||
"types": "./src/index.d.ts", | ||
"scripts": { | ||
@@ -45,2 +46,5 @@ "test": "jest" | ||
], | ||
"engines": { | ||
"node": ">= 6" | ||
}, | ||
"author": "George Kotchlamazashvili <georgedot@gmail.com>", | ||
@@ -53,4 +57,4 @@ "license": "MIT", | ||
"devDependencies": { | ||
"jest": "^23.6.0" | ||
"jest": "^25.1.0" | ||
} | ||
} |
@@ -0,1 +1,4 @@ | ||
const mkJDate = require('./_make_julian_date') | ||
const t = Math.trunc | ||
const g_julian_days_to_date = (julian_days) => { | ||
@@ -11,26 +14,15 @@ /* Formula taken from the Calendar FAQ; the formula was for the | ||
const A = julian_days + 1721425 + 32045; | ||
const B = Math.trunc(Math.trunc(4 * (A + 36524)) / 146097) - 1; | ||
const C = A - Math.trunc(Math.trunc(146097 * B) / 4); | ||
const D = Math.trunc(Math.trunc(4 * (C + 365)) / 1461) - 1; | ||
const E = C - Math.trunc(Math.trunc(1461 * D) / 4); | ||
const M = Math.trunc((Math.trunc(5 * (E - 1)) + 2) / 153); | ||
const B = t(t(4 * (A + 36524)) / 146097) - 1; | ||
const C = A - t(t(146097 * B) / 4); | ||
const D = t(t(4 * (C + 365)) / 1461) - 1; | ||
const E = C - t(t(1461 * D) / 4); | ||
const M = t((t(5 * (E - 1)) + 2) / 153); | ||
const m = M + 3 - Math.trunc(12 * Math.trunc(M / 10)); | ||
const day = E - Math.trunc((Math.trunc(153 * M) + 2) / 5); | ||
const y = Math.trunc(100 * B) + D - 4800 + Math.trunc(M / 10); | ||
const m = M + 3 - t(12 * t(M / 10)); | ||
const day = E - t((t(153 * M) + 2) / 5); | ||
const y = t(100 * B) + D - 4800 + t(M / 10); | ||
const dt = new Date | ||
dt.setUTCFullYear(y) | ||
dt.setUTCMonth(m - 1) | ||
dt.setUTCDate(day) | ||
//TODO: the hours part could be calculated based on the remaining fraction | ||
dt.setUTCHours(12) | ||
dt.setUTCMinutes(0) | ||
dt.setUTCSeconds(0) | ||
dt.setUTCMilliseconds(0) | ||
return dt | ||
return mkJDate(y, m - 1, day) | ||
} | ||
module.exports = g_julian_days_to_date |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4692
7
93