Merge pull request #370 from GVRLNKMK/fix-ceconitem-tradable-after-crash

Fix CEconItem crash when "Tradable/Marketable After" date isn't day-first
This commit is contained in:
DoctorMcKay
2026-07-12 17:09:19 -04:00
committed by GitHub

View File

@@ -70,19 +70,24 @@ function CEconItem(item, description, contextID, assetProperties) {
if (this.appid == 730 && this.contextid == 2 && this.owner_descriptions) {
let description = this.owner_descriptions.find((d) => d.value && d.value.indexOf("Tradable/Marketable After ") == 0);
if (description) {
let date;
const match = description.value.match(/(\d{1,2}) (\w+) @ (\d{1,2}:\d{2})(am|pm)/i);
const [, day, month, time, meridian] = match;
const now = new Date();
let year = now.getFullYear();
let date = new Date(`${day} ${month} ${year} ${time} ${meridian}`);
if (match) {
// New day-first format, e.g. "Tradable/Marketable After 17 Jul @ 3:00am"
const [, day, month, time, meridian] = match;
const now = new Date();
let year = now.getFullYear();
date = new Date(`${day} ${month} ${year} ${time} ${meridian}`);
if (date.getTime() < now.getTime()) {
date = new Date(
`${day} ${month} ${year + 1} ${time} ${meridian}`,
);
if (date.getTime() < now.getTime()) {
date = new Date(`${day} ${month} ${year + 1} ${time} ${meridian}`);
}
} else {
// Legacy month-first format, e.g. "Tradable/Marketable After Jul 11, 2025 (2:00:00)"
date = new Date(description.value.substring("Tradable/Marketable After ".length).replace(/[,()]/g, ""));
}
if (date) {
if (date && !isNaN(date.getTime())) {
this.cache_expiration = date.toISOString();
}
}