mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-29 23:36:12 +00:00
Keep usage ranges consistent across API and dashboards
Expose the active weekly subscription window through /v1/usage, calculate offsets with the same normalized page size used by queries, and keep user-facing date ranges on the browser's local calendar date. Constraint: Preserve existing response fields and avoid new dependencies Rejected: Keep duplicate inline date formatters | a shared local-date utility prevents the same UTC regression in both views Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep Offset and Limit based on the same normalized page size Tested: go test ./internal/pkg/pagination ./internal/handler; go vet ./internal/pkg/pagination ./internal/handler; frontend 923 tests; pnpm typecheck; pnpm lint:check; pnpm build Not-tested: Live API request against a deployed subscription Related: #4121
This commit is contained in:
1 parent
a1930ea6f2
commit
3605a316af
9 files changed
+149
-15
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { formatDateLocalInput } from '../format'
|
||||
|
||||
describe('formatDateLocalInput', () => {
|
||||
it('formats the calendar date in local time', () => {
|
||||
const localDate = new Date('2026-07-12T16:30:00Z')
|
||||
vi.spyOn(localDate, 'getFullYear').mockReturnValue(2026)
|
||||
vi.spyOn(localDate, 'getMonth').mockReturnValue(6)
|
||||
vi.spyOn(localDate, 'getDate').mockReturnValue(13)
|
||||
|
||||
expect(formatDateLocalInput(localDate)).toBe('2026-07-13')
|
||||
})
|
||||
|
||||
it('returns an empty string for an invalid date', () => {
|
||||
expect(formatDateLocalInput(new Date('invalid'))).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -149,6 +149,17 @@ export function formatDateTime(
|
||||
return formatDate(date, options, localeOverride)
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化为 date 控件值(YYYY-MM-DD,使用本地时间)
|
||||
*/
|
||||
export function formatDateLocalInput(date: Date): string {
|
||||
if (isNaN(date.getTime())) return ''
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化为 datetime-local 控件值(YYYY-MM-DDTHH:mm,使用本地时间)
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user