Skip to content

fix(xueqiu/kline,earnings-date): format dates in Asia/Shanghai instead of UTC#1498

Merged
jackwener merged 2 commits into
jackwener:mainfrom
Benjamin-eecs:fix/xueqiu-kline-date-tz
May 13, 2026
Merged

fix(xueqiu/kline,earnings-date): format dates in Asia/Shanghai instead of UTC#1498
jackwener merged 2 commits into
jackwener:mainfrom
Benjamin-eecs:fix/xueqiu-kline-date-tz

Conversation

@Benjamin-eecs
Copy link
Copy Markdown
Contributor

@Benjamin-eecs Benjamin-eecs commented May 12, 2026

Description

xueqiu/kline and xueqiu/earnings-date formatted bar timestamps with new Date(ts).toISOString().split('T')[0], which returns the UTC calendar date. xueqiu serves every market (China A-share, US, HK, etc.) on a Beijing-aligned timeline in its UI, so the UTC string is always one day earlier than the date the user actually sees on xueqiu.com.

Issue #1465 reports 5月10日跑的,5月8号的k线没有 because the May 8 China trading-day bar was labeled 2026-05-07. The same off-by-one was present in earnings-date.js.

Fix introduces formatChinaDate(ts) in clis/xueqiu/utils.js and routes both call sites through it. The helper uses toLocaleDateString('en-CA', { timeZone: 'Asia/Shanghai' }), which produces the ISO YYYY-MM-DD form in xueqiu's canonical timezone for all markets (verified live against both SZ300136 and AAPL).

Related issue: #1465

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/ (if new adapter)
  • Updated docs/adapters/index.md table (if new adapter)
  • Updated sidebar in docs/.vitepress/config.mts (if new adapter)
  • Updated README.md / README.zh-CN.md when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

(Only the date column value formatting moves from UTC to Asia/Shanghai. Argument shape and error contract unchanged.)

Screenshots / Output

SZ300136, default --days 14, run 2026-05-12:

Before: 04-19, 04-20, 04-21, 04-22, 04-23, 04-26, 04-27, 04-28, 04-29, 05-05, 05-06, 05-07, 05-10, 05-11
After:  04-20, 04-21, 04-22, 04-23, 04-24, 04-27, 04-28, 04-29, 04-30, 05-06, 05-07, 05-08, 05-11, 05-12

AAPL, --days 5, run 2026-05-12:

Before: 05-04, 05-05, 05-06, 05-07, 05-08   # UTC-shifted, mismatches xueqiu UI
After:  05-05, 05-06, 05-07, 05-08, 05-11   # Beijing dates, matches xueqiu UI

npx vitest run --project adapter clis/xueqiu/ 49/49 green (4 new cases in clis/xueqiu/utils.test.js pin the Asia/Shanghai semantics, including the 16:00 UTC day-boundary). npx tsc --noEmit clean. npm run build 815 manifest entries, unchanged shape. silent-column-drop / typed-error-lint baselines unchanged.

Closes #1465

Copilot AI review requested due to automatic review settings May 12, 2026 04:24
@Benjamin-eecs Benjamin-eecs force-pushed the fix/xueqiu-kline-date-tz branch from 0b5ad7b to a0d953f Compare May 12, 2026 04:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an off-by-one trading-day labeling bug in the xueqiu adapter by formatting kline and earnings-date timestamps as Asia/Shanghai calendar dates rather than UTC, aligning CLI output with what users see in the xueqiu UI.

Changes:

  • Added formatChinaDate(ts) helper to format timestamps in Asia/Shanghai as YYYY-MM-DD.
  • Updated xueqiu/kline and xueqiu/earnings-date to use the new helper instead of toISOString().
  • Added Vitest coverage for the new date-formatting helper.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
clis/xueqiu/utils.js Adds formatChinaDate to format dates in Asia/Shanghai rather than UTC.
clis/xueqiu/kline.js Uses formatChinaDate for the date field to avoid UTC day-shift.
clis/xueqiu/earnings-date.js Uses formatChinaDate for event date formatting.
clis/xueqiu/utils.test.js Adds unit tests pinning Asia/Shanghai date semantics and nullish handling.
Comments suppressed due to low confidence (1)

clis/xueqiu/utils.js:13

  • toLocaleDateString('en-CA', { timeZone: 'Asia/Shanghai' }) doesn’t guarantee a stable YYYY-MM-DD output across runtimes/locales (and may lose zero-padding), which could break downstream consumers expecting ISO dates. Consider using Intl.DateTimeFormat with explicit year/month/day options and assembling YYYY-MM-DD via formatToParts (similar to clis/tieba/utils.js’s formatTiebaUnixTime) to make the output format deterministic.
 * Fetch a xueqiu JSON API from inside the browser context (credentials included).
 * Page must already be navigated to xueqiu.com before calling this function.
 * Throws CliError on HTTP errors; otherwise returns the parsed JSON.
 */

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Benjamin-eecs Benjamin-eecs force-pushed the fix/xueqiu-kline-date-tz branch from a0d953f to a25c002 Compare May 12, 2026 04:30
@Benjamin-eecs Benjamin-eecs changed the title fix(xueqiu/kline,earnings-date): format dates in Asia/Shanghai instead of UTC (#1465) fix(xueqiu/kline,earnings-date): format dates in Asia/Shanghai instead of UTC May 12, 2026
@Benjamin-eecs Benjamin-eecs force-pushed the fix/xueqiu-kline-date-tz branch 2 times, most recently from 2d8dd6e to daf68af Compare May 12, 2026 14:10
…d of UTC (jackwener#1465)

`xueqiu/kline` and `xueqiu/earnings-date` formatted bar timestamps with
`new Date(ts).toISOString().split('T')[0]`. That string is the UTC
calendar date, always one day earlier than the date xueqiu shows in its
UI (which is Beijing-aligned for every market). Issue jackwener#1465 reports
"5月10日跑的,5月8号的k线没有" because the May 8 China trading-day bar
was labeled 2026-05-07. Same off-by-one was present in `earnings-date.js`.

Routes both call sites through a new `formatChinaDate(ts)` helper in
`clis/xueqiu/utils.js` built on `toLocaleDateString('en-CA', { timeZone:
'Asia/Shanghai' })`. Verified live against SZ300136 and AAPL: both now
match the dates shown on xueqiu.com.

Tests: `clis/xueqiu/utils.test.js` (new) pins the Asia/Shanghai semantic
with 4 cases (China midnight, late-evening, 16:00 UTC day boundary, and
nullish input). `npx vitest run --project adapter clis/xueqiu/` 49/49,
`npx tsc --noEmit` clean, `npm run build` 815 entries unchanged shape.

Closes jackwener#1465
@Benjamin-eecs Benjamin-eecs force-pushed the fix/xueqiu-kline-date-tz branch from daf68af to 41d2910 Compare May 12, 2026 15:11
@jackwener jackwener merged commit 6af4db2 into jackwener:main May 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: xueqiu kline 获取缺少数据

3 participants