DIYgod/RSSHub · error · Error
Invalid endDate format. Expected YYYY-MM-DD
Error message
Invalid endDate format. Expected YYYY-MM-DD
What it means
Thrown by szse/disclosure/listed-notice.ts:48 via `throw new Error(...)` (NOT an InvalidParameterError) when an explicit endDate fails isValidDate (strict YYYY-MM-DD + real-calendar). Only checked when endDate is truthy. If endDate is OMITTED but beginDate is set, the code silently copies beginDate into endDate (line 52) — no error — so this fires only on an explicit-but-malformed endDate.
Source
Thrown at lib/routes/szse/disclosure/listed-notice.ts:48
const queries: Record<string, string> = {
stock: '',
beginDate: '',
endDate: '',
};
if (query) {
for (const pair of query.split('&')) {
const [key, value] = pair.split('=', 2);
if (key) {
queries[key] = value;
}
}
}
if (queries.beginDate && !isValidDate(queries.beginDate)) {
throw new Error('Invalid beginDate format. Expected YYYY-MM-DD');
}
if (queries.endDate) {
if (!isValidDate(queries.endDate)) {
throw new Error('Invalid endDate format. Expected YYYY-MM-DD');
}
} else if (queries.beginDate) {
// 如果只提供了开始日期,则将结束日期设置为开始日期
queries.endDate = queries.beginDate;
}
const baseUrl = 'https://www.szse.cn';
const staticBaseUrl = 'https://disc.static.szse.cn';
const apiUrl: string = new URL('api/disc/announcement/annList', baseUrl).href;
const targetUrl: string = new URL(`disclosure/listed/notice${category}`, baseUrl).href;
const targetResponse = await ofetch(targetUrl);
const $: CheerioAPI = load(targetResponse);
const language = $('html').attr('lang') ?? 'zh-CN';
const response = await ofetch(apiUrl, {
method: 'POST',
body: {
stock: queries.stock ? [queries.stock] : [],
seDate: [queries.beginDate, queries.endDate],View on GitHub (pinned to bed535e087)
Solutions
- Use strict YYYY-MM-DD with leading zeros for endDate.
- Omit endDate entirely to default it to beginDate (single-day query).
Example fix
// before GET /szse/disclosure/listed/notice/beginDate=2025-02-03&endDate=2025-2-30 // after GET /szse/disclosure/listed/notice/beginDate=2025-02-03&endDate=2025-02-28
Defensive patterns
Strategy: validation
Validate before calling
function isValidDate(dateString: string): boolean {
if (!/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/.test(dateString)) {
return false;
}
const [y, m, d] = dateString.split('-').map(Number);
const date = new Date(y, m - 1, d);
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
}
// Omit endDate to default it to beginDate; otherwise validate strictly.
if (endDate && !isValidDate(endDate)) {
// reject client-side
} Type guard
function isStrictYmd(s: string): s is string {
if (!/^\d{4}-\d{2}-\d{2}$/.test(s)) return false;
const [y, m, d] = s.split('-').map(Number);
const date = new Date(y, m - 1, d);
return date.getFullYear() === y && date.getMonth() === m - 1 && date.getDate() === d;
} Prevention
- Use strict YYYY-MM-DD with leading zeros for endDate.
- Omit endDate when you want a single-day query (it defaults to beginDate).
- Keep the same format for beginDate and endDate to avoid mismatches.
When it happens
Trigger: endDate=2025-02-30, endDate=2025/02/03, endDate=2025-13-01, endDate=2025-2-3 — any explicit value failing the strict date check.
Common situations: Inconsistent date formatting between beginDate and endDate; copying from a different locale format;endDate accidentally before beginDate is NOT caught here (the upstream API may reject it later).
Related errors
- Invalid beginDate format. Expected YYYY-MM-DD
- Unsupported game: ${game}. Supported games: ${Object.keys(GA
- Invalid category
- At least one valid search parameter is required
- 无法检测 Discuz 版本,请在路由中指定版本参数,如 /discuz/x/ 或 /discuz/7/
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/536436d3a8aa2098.
Report an issue: GitHub.