refactor announcement date handling to support 'soon' and streamline date parsing logic
All checks were successful
CI / build (push) Successful in 9s
All checks were successful
CI / build (push) Successful in 9s
This commit is contained in:
@@ -108,35 +108,43 @@ export default async function (_client: Client) {
|
|||||||
if (comingWhenRaw && comingWhenRaw.trim() !== "") {
|
if (comingWhenRaw && comingWhenRaw.trim() !== "") {
|
||||||
let epoch: number | null = null;
|
let epoch: number | null = null;
|
||||||
const trimmed = comingWhenRaw.trim();
|
const trimmed = comingWhenRaw.trim();
|
||||||
// Try DD/MM/YYYY
|
if (trimmed.toLowerCase() === "soon") {
|
||||||
const ddmmyyyy = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(
|
|
||||||
trimmed,
|
|
||||||
);
|
|
||||||
if (ddmmyyyy) {
|
|
||||||
const [, dd, mm, yyyy] = ddmmyyyy;
|
|
||||||
const date = new Date(
|
|
||||||
Number(yyyy),
|
|
||||||
Number(mm) - 1,
|
|
||||||
Number(dd),
|
|
||||||
);
|
|
||||||
if (!isNaN(date.getTime()))
|
|
||||||
epoch = Math.floor(date.getTime() / 1000);
|
|
||||||
} else if (/^\d+$/.test(trimmed)) {
|
|
||||||
// Raw epoch
|
|
||||||
epoch = Number(trimmed);
|
|
||||||
}
|
|
||||||
if (epoch !== null) {
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "📅 Coming On",
|
name: "📅 Coming On",
|
||||||
value: `<t:${epoch}:F> (<t:${epoch}:R>)`,
|
value: "Soon™",
|
||||||
inline: false,
|
inline: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fields.push({
|
// Try DD/MM/YYYY
|
||||||
name: "📅 Coming On",
|
const ddmmyyyy = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(
|
||||||
value: trimmed,
|
trimmed,
|
||||||
inline: false,
|
);
|
||||||
});
|
if (ddmmyyyy) {
|
||||||
|
const [, dd, mm, yyyy] = ddmmyyyy;
|
||||||
|
const date = new Date(
|
||||||
|
Number(yyyy),
|
||||||
|
Number(mm) - 1,
|
||||||
|
Number(dd),
|
||||||
|
);
|
||||||
|
if (!isNaN(date.getTime()))
|
||||||
|
epoch = Math.floor(date.getTime() / 1000);
|
||||||
|
} else if (/^\d+$/.test(trimmed)) {
|
||||||
|
// Raw epoch
|
||||||
|
epoch = Number(trimmed);
|
||||||
|
}
|
||||||
|
if (epoch !== null) {
|
||||||
|
fields.push({
|
||||||
|
name: "📅 Coming On",
|
||||||
|
value: `<t:${epoch}:F> (<t:${epoch}:R>)`,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fields.push({
|
||||||
|
name: "📅 Coming On",
|
||||||
|
value: trimmed,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,31 +128,41 @@ export default async function (_client: Client) {
|
|||||||
if (comingWhenRaw && comingWhenRaw.trim() !== "") {
|
if (comingWhenRaw && comingWhenRaw.trim() !== "") {
|
||||||
let epoch: number | null = null;
|
let epoch: number | null = null;
|
||||||
const trimmed = comingWhenRaw.trim();
|
const trimmed = comingWhenRaw.trim();
|
||||||
const ddmmyyyy = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(trimmed);
|
if (trimmed.toLowerCase() === "soon") {
|
||||||
if (ddmmyyyy) {
|
|
||||||
const [, dd, mm, yyyy] = ddmmyyyy;
|
|
||||||
const date = new Date(
|
|
||||||
Number(yyyy),
|
|
||||||
Number(mm) - 1,
|
|
||||||
Number(dd),
|
|
||||||
);
|
|
||||||
if (!isNaN(date.getTime()))
|
|
||||||
epoch = Math.floor(date.getTime() / 1000);
|
|
||||||
} else if (/^\d+$/.test(trimmed)) {
|
|
||||||
epoch = Number(trimmed);
|
|
||||||
}
|
|
||||||
if (epoch !== null) {
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: "📅 Coming On",
|
name: "📅 Coming On",
|
||||||
value: `<t:${epoch}:F> (<t:${epoch}:R>)`,
|
value: "Soon™",
|
||||||
inline: false,
|
inline: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
fields.push({
|
const ddmmyyyy = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(
|
||||||
name: "📅 Coming On",
|
trimmed,
|
||||||
value: trimmed,
|
);
|
||||||
inline: false,
|
if (ddmmyyyy) {
|
||||||
});
|
const [, dd, mm, yyyy] = ddmmyyyy;
|
||||||
|
const date = new Date(
|
||||||
|
Number(yyyy),
|
||||||
|
Number(mm) - 1,
|
||||||
|
Number(dd),
|
||||||
|
);
|
||||||
|
if (!isNaN(date.getTime()))
|
||||||
|
epoch = Math.floor(date.getTime() / 1000);
|
||||||
|
} else if (/^\d+$/.test(trimmed)) {
|
||||||
|
epoch = Number(trimmed);
|
||||||
|
}
|
||||||
|
if (epoch !== null) {
|
||||||
|
fields.push({
|
||||||
|
name: "📅 Coming On",
|
||||||
|
value: `<t:${epoch}:F> (<t:${epoch}:R>)`,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fields.push({
|
||||||
|
name: "📅 Coming On",
|
||||||
|
value: trimmed,
|
||||||
|
inline: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user