mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-30 16:23:31 +00:00
feat(subscription): show expiry times to minute
This commit is contained in:
@@ -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('')
|
||||
})
|
||||
})
|
||||
@@ -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,使用本地时间)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user