mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-10 03:27:54 +00:00
fix(skill): format publish time in local system time
This commit is contained in:
parent
fc9bdffc7d
commit
32add06b5d
2 changed files with 23 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ import { RatingInput } from '@/features/social/rating-input'
|
|||
import { StarButton } from '@/features/social/star-button'
|
||||
import { useAuth } from '@/features/auth/use-auth'
|
||||
import { adminApi } from '@/api/client'
|
||||
import { formatLocalDateTime } from '@/shared/lib/date-time'
|
||||
import { NamespaceBadge } from '@/shared/components/namespace-badge'
|
||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/shared/ui/tabs'
|
||||
import { Button } from '@/shared/ui/button'
|
||||
|
|
@ -191,7 +192,7 @@ export function SkillDetailPage() {
|
|||
</span>
|
||||
</span>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{new Date(version.publishedAt).toLocaleDateString(i18n.language)}
|
||||
{formatLocalDateTime(version.publishedAt, i18n.language)}
|
||||
</span>
|
||||
</div>
|
||||
{version.changelog && (
|
||||
|
|
|
|||
21
web/src/shared/lib/date-time.ts
Normal file
21
web/src/shared/lib/date-time.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function parseServerDateTime(value: string): Date {
|
||||
if (/[zZ]$|[+-]\d{2}:\d{2}$/.test(value)) {
|
||||
return new Date(value)
|
||||
}
|
||||
|
||||
const [datePart, timePart = '00:00:00'] = value.split('T')
|
||||
const [year, month, day] = datePart.split('-').map(Number)
|
||||
const [rawTime, fractional = ''] = timePart.split('.')
|
||||
const [hours = 0, minutes = 0, seconds = 0] = rawTime.split(':').map(Number)
|
||||
const milliseconds = Number((fractional + '000').slice(0, 3))
|
||||
|
||||
return new Date(year, (month || 1) - 1, day || 1, hours, minutes, seconds, milliseconds)
|
||||
}
|
||||
|
||||
export function formatLocalDateTime(
|
||||
value: string,
|
||||
locale: string,
|
||||
options: Intl.DateTimeFormatOptions = { dateStyle: 'medium', timeStyle: 'short' },
|
||||
) {
|
||||
return new Intl.DateTimeFormat(locale, options).format(parseServerDateTime(value))
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue