sync time.ts specific code to fix typecheck

This commit is contained in:
Alex Yaroshuk
2026-03-01 05:29:04 +08:00
parent b9ca79f3b6
commit 9ea36ccd9d
19 changed files with 82 additions and 8 deletions

View File

@@ -1,5 +1,4 @@
import type { Platform } from "@/context/platform"
import { getRelativeTime } from "@/utils/time"
const REPO = "anomalyco/opencode"
const GITHUB_API_URL = `https://api.github.com/repos/${REPO}/releases`
@@ -40,7 +39,7 @@ export async function fetchReleases(platform: Platform): Promise<{ releases: Rel
body: (r.body ?? "")
.replace(/#(\d+)/g, (_: string, id: string) => `[#${id}](https://github.com/anomalyco/opencode/pull/${id})`)
.replace(/@([a-zA-Z0-9_-]+)/g, (_: string, u: string) => `[@${u}](https://github.com/${u})`),
date: r.published_at ? getRelativeTime(r.published_at) : "",
date: r.published_at ?? "",
}))
saveCache({ releases, timestamp: now })

View File

@@ -4,6 +4,7 @@ import { Markdown } from "@opencode-ai/ui/markdown"
import { Button } from "@opencode-ai/ui/button"
import { Tag } from "@opencode-ai/ui/tag"
import { useLanguage } from "@/context/language"
import { getRelativeTime } from "@/utils/time"
type Release = {
tag: string
@@ -44,7 +45,7 @@ export const ReleaseList: Component<ReleaseListProps> = (props) => {
<div class="mb-8">
<div class="py-2 pr-3 pl-2 flex items-baseline gap-2 sticky top-0 z-10 bg-surface-raised-stronger-non-alpha">
<span class="text-[20px] font-semibold">{item.tag}</span>
<span class="text-xs text-text-weak">{item.date}</span>
<span class="text-xs text-text-weak">{item.date ? getRelativeTime(item.date, language.t) : ""}</span>
{item.tag === props.releases[0]?.tag && <Tag>{language.t("changelog.tag.latest")}</Tag>}
</div>
<div class="px-2 pb-2">

View File

@@ -509,6 +509,12 @@ export const dict = {
"common.changelog": "التغييرات",
"common.noReleasesFound": "لم يتم العثور على إصدارات",
"changelog.tag.latest": "الأحدث",
"common.time.justNow": "الآن",
"common.time.minutesAgo.short": "قبل {{count}} د",
"common.time.hoursAgo.short": "قبل {{count}} س",
"common.time.daysAgo.short": "قبل {{count}} ي",
"common.key.esc": "ESC",
"sidebar.menu.toggle": "تبديل القائمة",
"sidebar.nav.projectsAndSessions": "المشاريع والجلسات",

View File

@@ -514,6 +514,10 @@ export const dict = {
"common.loadMore": "Carregar mais",
"common.changelog": "Novidades",
"common.noReleasesFound": "Nenhuma release encontrada",
"common.time.justNow": "Agora mesmo",
"common.time.minutesAgo.short": "{{count}}m atrás",
"common.time.hoursAgo.short": "{{count}}h atrás",
"common.time.daysAgo.short": "{{count}}d atrás",
"changelog.tag.latest": "Mais recente",
"common.key.esc": "ESC",
"sidebar.menu.toggle": "Alternar menu",

View File

@@ -574,6 +574,10 @@ export const dict = {
"common.loadMore": "Učitaj još",
"common.changelog": "Novosti",
"common.noReleasesFound": "Nema pronađenih verzija",
"common.time.justNow": "Upravo sada",
"common.time.minutesAgo.short": "prije {{count}} min",
"common.time.hoursAgo.short": "prije {{count}} h",
"common.time.daysAgo.short": "prije {{count}} d",
"changelog.tag.latest": "Najnovije",
"common.key.esc": "ESC",

View File

@@ -570,6 +570,10 @@ export const dict = {
"common.loadMore": "Indlæs flere",
"common.changelog": "Nyheder",
"common.noReleasesFound": "Ingen versioner fundet",
"common.time.justNow": "Lige nu",
"common.time.minutesAgo.short": "{{count}}m siden",
"common.time.hoursAgo.short": "{{count}}t siden",
"common.time.daysAgo.short": "{{count}}d siden",
"changelog.tag.latest": "Seneste",
"common.key.esc": "ESC",

View File

@@ -522,6 +522,10 @@ export const dict = {
"common.loadMore": "Mehr laden",
"common.changelog": "Neuerungen",
"common.noReleasesFound": "Keine Versionen gefunden",
"common.time.justNow": "Gerade eben",
"common.time.minutesAgo.short": "vor {{count}} Min",
"common.time.hoursAgo.short": "vor {{count}} Std",
"common.time.daysAgo.short": "vor {{count}} Tg",
"changelog.tag.latest": "Neueste",
"common.key.esc": "ESC",

View File

@@ -576,6 +576,10 @@ export const dict = {
"common.loadMore": "Load more",
"common.changelog": "Changelog",
"common.noReleasesFound": "No releases found",
"common.time.justNow": "Just now",
"common.time.minutesAgo.short": "{{count}}m ago",
"common.time.hoursAgo.short": "{{count}}h ago",
"common.time.daysAgo.short": "{{count}}d ago",
"changelog.tag.latest": "Latest",
"common.key.esc": "ESC",

View File

@@ -577,6 +577,10 @@ export const dict = {
"common.loadMore": "Cargar más",
"common.changelog": "Novedades",
"common.noReleasesFound": "No se encontraron versiones",
"common.time.justNow": "Justo ahora",
"common.time.minutesAgo.short": "hace {{count}} min",
"common.time.hoursAgo.short": "hace {{count}} h",
"common.time.daysAgo.short": "hace {{count}} d",
"changelog.tag.latest": "Último",
"common.key.esc": "ESC",

View File

@@ -520,6 +520,10 @@ export const dict = {
"common.loadMore": "Charger plus",
"common.changelog": "Nouveautés",
"common.noReleasesFound": "Aucune version trouvée",
"common.time.justNow": "À l'instant",
"common.time.minutesAgo.short": "il y a {{count}}m",
"common.time.hoursAgo.short": "il y a {{count}}h",
"common.time.daysAgo.short": "il y a {{count}}j",
"changelog.tag.latest": "Dernier",
"common.key.esc": "ESC",

View File

@@ -512,6 +512,10 @@ export const dict = {
"common.loadMore": "さらに読み込む",
"common.changelog": "更新履歴",
"common.noReleasesFound": "バージョンが見つかりません",
"common.time.justNow": "たった今",
"common.time.minutesAgo.short": "{{count}} 分前",
"common.time.hoursAgo.short": "{{count}} 時間前",
"common.time.daysAgo.short": "{{count}} 日前",
"changelog.tag.latest": "最新",
"common.key.esc": "ESC",

View File

@@ -513,6 +513,10 @@ export const dict = {
"common.loadMore": "더 불러오기",
"common.changelog": "새로운 기능",
"common.noReleasesFound": "버전을 찾을 수 없음",
"common.time.justNow": "방금 전",
"common.time.minutesAgo.short": "{{count}}분 전",
"common.time.hoursAgo.short": "{{count}}시간 전",
"common.time.daysAgo.short": "{{count}}일 전",
"changelog.tag.latest": "최신",
"common.key.esc": "ESC",

View File

@@ -577,6 +577,10 @@ export const dict = {
"common.loadMore": "Last flere",
"common.changelog": "Nyheter",
"common.noReleasesFound": "Ingen versjoner funnet",
"common.time.justNow": "Akkurat nå",
"common.time.minutesAgo.short": "{{count}} m siden",
"common.time.hoursAgo.short": "{{count}} t siden",
"common.time.daysAgo.short": "{{count}} d siden",
"changelog.tag.latest": "Siste",
"common.key.esc": "ESC",

View File

@@ -513,6 +513,10 @@ export const dict = {
"common.loadMore": "Załaduj więcej",
"common.changelog": "Nowości",
"common.noReleasesFound": "Nie znaleziono wersji",
"common.time.justNow": "Przed chwilą",
"common.time.minutesAgo.short": "{{count}} min temu",
"common.time.hoursAgo.short": "{{count}} godz. temu",
"common.time.daysAgo.short": "{{count}} dni temu",
"changelog.tag.latest": "Najnowszy",
"common.key.esc": "ESC",
"sidebar.menu.toggle": "Przełącz menu",

View File

@@ -575,6 +575,10 @@ export const dict = {
"common.loadMore": "Загрузить ещё",
"common.changelog": "Что нового",
"common.noReleasesFound": "Версии не найдены",
"common.time.justNow": "Только что",
"common.time.minutesAgo.short": "{{count}} мин назад",
"common.time.hoursAgo.short": "{{count}} ч назад",
"common.time.daysAgo.short": "{{count}} д назад",
"changelog.tag.latest": "Последний",
"common.key.esc": "ESC",

View File

@@ -569,6 +569,10 @@ export const dict = {
"common.loadMore": "โหลดเพิ่มเติม",
"common.changelog": "อัปเดต",
"common.noReleasesFound": "ไม่พบเวอร์ชัน",
"common.time.justNow": "เมื่อสักครู่นี้",
"common.time.minutesAgo.short": "{{count}} นาทีที่แล้ว",
"common.time.hoursAgo.short": "{{count}} ชม. ที่แล้ว",
"common.time.daysAgo.short": "{{count}} วันที่แล้ว",
"changelog.tag.latest": "ล่าสุด",
"common.key.esc": "ESC",

View File

@@ -568,6 +568,10 @@ export const dict = {
"common.loadMore": "加载更多",
"common.changelog": "更新日志",
"common.noReleasesFound": "未找到版本",
"common.time.justNow": "刚刚",
"common.time.minutesAgo.short": "{{count}}分钟前",
"common.time.hoursAgo.short": "{{count}}小时前",
"common.time.daysAgo.short": "{{count}}天前",
"changelog.tag.latest": "最新",
"common.key.esc": "ESC",

View File

@@ -565,6 +565,10 @@ export const dict = {
"common.loadMore": "載入更多",
"common.changelog": "更新日誌",
"common.noReleasesFound": "未找到版本",
"common.time.justNow": "剛剛",
"common.time.minutesAgo.short": "{{count}}分鐘前",
"common.time.hoursAgo.short": "{{count}}小時前",
"common.time.daysAgo.short": "{{count}}天前",
"changelog.tag.latest": "最新",
"common.key.esc": "ESC",

View File

@@ -1,4 +1,12 @@
export function getRelativeTime(dateString: string): string {
type TimeKey =
| "common.time.justNow"
| "common.time.minutesAgo.short"
| "common.time.hoursAgo.short"
| "common.time.daysAgo.short"
export type Translate = (key: TimeKey, params?: Record<string, string | number>) => string
export function getRelativeTime(dateString: string, t: Translate): string {
const date = new Date(dateString)
const now = new Date()
const diffMs = now.getTime() - date.getTime()
@@ -7,8 +15,8 @@ export function getRelativeTime(dateString: string): string {
const diffHours = Math.floor(diffMinutes / 60)
const diffDays = Math.floor(diffHours / 24)
if (diffSeconds < 60) return "Just now"
if (diffMinutes < 60) return `${diffMinutes}m ago`
if (diffHours < 24) return `${diffHours}h ago`
return `${diffDays}d ago`
if (diffSeconds < 60) return t("common.time.justNow")
if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes })
if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours })
return t("common.time.daysAgo.short", { count: diffDays })
}