mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 14:38:24 +00:00
* feat(quota): add database-backed resource quota system * feat(webui): add resource quota management in team settings (#319) * feat(webui): add resource quota settings in team management * refactor(webui): update quotas list to full row layout and restrict skill/mcp to select list * feat(quota): refactor quota system to 2-level rules and records * fix(webui): fix overflow and scroll area in quota usage records dialog * fix(webui): ensure quota records scroll area has explicit max height * feat(webui): improve quota cards interaction and restrict editable fields in edit mode * fix(quota): serialize initial records, validate merged updates, and reset on dimension changes (#320) * feat(quota): replace network quota with agent tools quota (#321) * feat(webui): show remaining time until next refresh in quota usage records * fix(webui): rename bash quota resource to Agent Bash Calls * refactor(quota): remove unused reserved field from quota records * refactor(quota): remove quota rule cache (#322)
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { differenceInDays, format, isToday, isYesterday, parseISO } from 'date-fns'
|
|
import { m } from '@/ui/paraglide/messages.js'
|
|
|
|
export const formatTimeAgo = (dateString: string) => {
|
|
const date = parseISO(dateString)
|
|
const now = new Date()
|
|
|
|
if (isNaN(date.getTime())) {
|
|
return dateString
|
|
}
|
|
|
|
const time = format(date, 'HH:mm')
|
|
|
|
if (isToday(date)) {
|
|
return m.today_with_time({ time })
|
|
}
|
|
if (isYesterday(date)) {
|
|
return m.yesterday_with_time({ time })
|
|
}
|
|
|
|
const daysAgo = differenceInDays(now, date)
|
|
const count = daysAgo >= 0 ? daysAgo : 0
|
|
return count === 1 ? m.n_days_ago_singular({ count }) : m.n_days_ago_plural({ count })
|
|
}
|
|
|
|
export const formatDateAgo = (dateString: string) => {
|
|
const date = parseISO(dateString)
|
|
const now = new Date()
|
|
|
|
if (isNaN(date.getTime())) {
|
|
return dateString
|
|
}
|
|
|
|
if (isToday(date)) {
|
|
return m.today()
|
|
}
|
|
if (isYesterday(date)) {
|
|
return m.yesterday()
|
|
}
|
|
|
|
const daysAgo = differenceInDays(now, date)
|
|
const count = daysAgo >= 0 ? daysAgo : 0
|
|
return count === 1 ? m.n_days_ago_singular({ count }) : m.n_days_ago_plural({ count })
|
|
}
|
|
|
|
export const formatRemainingTime = (targetDate: string | Date, now: Date = new Date()): string => {
|
|
const targetMs =
|
|
typeof targetDate === 'string'
|
|
? parseISO(targetDate).getTime()
|
|
: targetDate instanceof Date
|
|
? targetDate.getTime()
|
|
: NaN
|
|
if (isNaN(targetMs)) {
|
|
return '< 1m'
|
|
}
|
|
const diffMs = targetMs - now.getTime()
|
|
if (diffMs <= 0) {
|
|
return '< 1m'
|
|
}
|
|
|
|
const totalSeconds = Math.floor(diffMs / 1000)
|
|
const days = Math.floor(totalSeconds / 86400)
|
|
const hours = Math.floor((totalSeconds % 86400) / 3600)
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
|
|
if (days > 0) {
|
|
return hours > 0 ? `${days}d ${hours}h` : `${days}d`
|
|
}
|
|
if (hours > 0) {
|
|
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`
|
|
}
|
|
return minutes > 0 ? `${minutes}m` : '< 1m'
|
|
}
|