feat(subscription): show expiry times to minute

This commit is contained in:
cugxuan
2026-07-19 22:43:35 +08:00
parent d4b9797ff7
commit 3379603022
4 changed files with 41 additions and 5 deletions
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { formatDateTimeToMinute } from '../format'
describe('formatDateTimeToMinute', () => {
it('formats local date and time without seconds', () => {
const value = new Date(2026, 6, 19, 20, 30, 45)
expect(formatDateTimeToMinute(value, 'en-GB')).toBe('19/07/2026, 20:30')
})
it('returns an empty string for an invalid date', () => {
expect(formatDateTimeToMinute(new Date('invalid'), 'en-GB')).toBe('')
})
})
+21
View File
@@ -149,6 +149,27 @@ export function formatDateTime(
return formatDate(date, options, localeOverride)
}
/**
* 格式化日期时间(精确到分钟)
*/
export function formatDateTimeToMinute(
date: string | Date | null | undefined,
localeOverride?: string
): string {
return formatDate(
date,
{
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false
},
localeOverride
)
}
/**
* 格式化为 date 控件值(YYYY-MM-DD,使用本地时间)
*/