UNPKG

pricehistory

Version:
44 lines (43 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const simpul_1 = require("simpul"); const premarketStart = 4 * 60; // 4:00 AM const regularStart = 9 * 60 + 30; // 9:30 AM const regularEnd = 16 * 60; // 4:00 PM const postmarketEnd = 20 * 60; // 8:00 PM function setCandleTime(option, candle, prev) { var _a; if (option.time !== true || !candle.dateObject) return; candle.timeHour = candle.dateObject.getHours(); candle.timeHourQuarter = Math.floor(candle.dateObject.getMinutes() / 15) + 1; candle.timeMinute = candle.dateObject.getMinutes(); const candleTimestamp = candle.dateObject.getTime(); const prevTimestamp = (_a = prev === null || prev === void 0 ? void 0 : prev.dateObject) === null || _a === void 0 ? void 0 : _a.getTime(); if (typeof candleTimestamp === "number" && typeof prevTimestamp === "number") { candle.timeSpan = candleTimestamp - prevTimestamp; const timeElapsed = Date.now() - candleTimestamp; candle.timeTillNext = Math.max(candle.timeSpan - timeElapsed, 0); candle.timeTillNextProgress = 100 - (simpul_1.math.percent(candle.timeTillNext, candle.timeSpan) || 0); } const options = { timeZone: "America/New_York", hour12: false, }; const hours = parseInt(candle.dateObject.toLocaleString("en-US", Object.assign(Object.assign({}, options), { hour: "2-digit" }))); const minutes = parseInt(candle.dateObject.toLocaleString("en-US", Object.assign(Object.assign({}, options), { minute: "2-digit" }))); const totalMinutes = hours * 60 + minutes; candle.timeIsPremarket = totalMinutes >= premarketStart && totalMinutes < regularStart; candle.timeIsIntraday = totalMinutes >= regularStart && totalMinutes < regularEnd; candle.timeIsPostmarket = totalMinutes >= regularEnd && totalMinutes <= postmarketEnd; candle.timeIsDark = !candle.timeIsPremarket && !candle.timeIsIntraday && !candle.timeIsPostmarket; } exports.default = setCandleTime;