UNPKG

maycur-business

Version:

maycur business react components of web

65 lines (54 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = parsedate; var _constants = require("./constants"); var _error = require("./error"); var _isnan = _interopRequireDefault(require("./isnan")); var _isdate = _interopRequireDefault(require("./isdate")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } // Copyright 2015-2018 FormBucket LLC // PARSEDATE converts a value into a Date object. function parsedate(val) { /* ******************* Extracted from Social Calc convert_date_julian_to_gregorian(juliandate) ymd->{} .year .month .day From: http://aa.usno.navy.mil/faq/docs/JD_Formula.html Uses: Fliegel, H. F. and van Flandern, T. C. (1968). Communications of the ACM, Vol. 11, No. 10 (October, 1968). Translated from the FORTRAN ************************* */ function convert_date_julian_to_gregorian(juliandate) { var L, N, I, J, K; L = juliandate + 68569; N = Math.floor(4 * L / 146097); L = L - Math.floor((146097 * N + 3) / 4); I = Math.floor(4000 * (L + 1) / 1461001); L = L - Math.floor(1461 * I / 4) + 31; J = Math.floor(80 * L / 2447); K = L - Math.floor(2447 * J / 80); L = Math.floor(J / 11); J = J + 2 - 12 * L; I = 100 * (N - 49) + I + L; return new Date(I, J - 1, K); } if (val instanceof Error) { return val; } else if ((0, _isdate["default"])(val)) { return val; } else if (typeof val === "number") { // val is assumed to be serial number. return convert_date_julian_to_gregorian(Math.floor(val + _constants.JulianOffset)); } else if (typeof val === "string") { var timestamp = Date.parse(val); if ((0, _isnan["default"])(timestamp)) { return _error.ERRORTYPES.value; } return new Date(timestamp); } return _error.ERRORTYPES.value; }