fix: UTC+8 market chart times and archive full history K-line load
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -79,6 +79,69 @@
|
||||
"1w": "周线",
|
||||
};
|
||||
const TF_DIGIT_TIMEOUT_MS = 650;
|
||||
const CHART_TZ_OFFSET_SEC = 8 * 60 * 60;
|
||||
|
||||
function pad2(n) {
|
||||
return n < 10 ? "0" + n : String(n);
|
||||
}
|
||||
|
||||
function utcSecToBjDate(utcSec) {
|
||||
return new Date((Number(utcSec) + CHART_TZ_OFFSET_SEC) * 1000);
|
||||
}
|
||||
|
||||
function formatChartTimeBj(utcSec, withDate) {
|
||||
const d = utcSecToBjDate(utcSec);
|
||||
const h = pad2(d.getUTCHours());
|
||||
const mi = pad2(d.getUTCMinutes());
|
||||
if (!withDate) return h + ":" + mi;
|
||||
return (
|
||||
d.getUTCFullYear() +
|
||||
"-" +
|
||||
pad2(d.getUTCMonth() + 1) +
|
||||
"-" +
|
||||
pad2(d.getUTCDate()) +
|
||||
" " +
|
||||
h +
|
||||
":" +
|
||||
mi
|
||||
);
|
||||
}
|
||||
|
||||
function chartLocalizationBj() {
|
||||
return {
|
||||
locale: "zh-CN",
|
||||
dateFormat: "yyyy-MM-dd",
|
||||
timeFormatter: function (time) {
|
||||
if (typeof time === "number") return formatChartTimeBj(time, true);
|
||||
if (time && typeof time === "object" && time.year) {
|
||||
return time.year + "-" + pad2(time.month) + "-" + pad2(time.day);
|
||||
}
|
||||
return "";
|
||||
},
|
||||
tickMarkFormatter: function (time, tickMarkType) {
|
||||
if (typeof time !== "number") {
|
||||
if (time && typeof time === "object" && time.year) {
|
||||
return time.year + "-" + pad2(time.month) + "-" + pad2(time.day);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
const d = utcSecToBjDate(time);
|
||||
if (tickMarkType === 0) return String(d.getUTCFullYear());
|
||||
if (tickMarkType === 1) return pad2(d.getUTCMonth() + 1);
|
||||
if (tickMarkType === 2) return pad2(d.getUTCDate());
|
||||
return formatChartTimeBj(time, false);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function buildChartLocalization() {
|
||||
const loc = chartLocalizationBj();
|
||||
loc.priceFormatter = function (p) {
|
||||
return fmtPrice(p);
|
||||
};
|
||||
return loc;
|
||||
}
|
||||
|
||||
const chartHost = document.getElementById("market-chart");
|
||||
if (!chartHost) return;
|
||||
|
||||
@@ -1649,11 +1712,7 @@
|
||||
applyPriceFormatToSeries(indSeries.ema55, pf);
|
||||
if (chart) {
|
||||
chart.applyOptions({
|
||||
localization: {
|
||||
priceFormatter: function (p) {
|
||||
return fmtPrice(p);
|
||||
},
|
||||
},
|
||||
localization: buildChartLocalization(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1933,6 +1992,7 @@
|
||||
horzLines: { visible: false },
|
||||
},
|
||||
rightPriceScale: { borderColor: tp.border, autoScale: true },
|
||||
localization: buildChartLocalization(),
|
||||
timeScale: {
|
||||
borderColor: tp.border,
|
||||
timeVisible: true,
|
||||
|
||||
Reference in New Issue
Block a user