fix: 修正 markdown-to-jsx 导入方式 + 新增 formatDateLabel 日期工具函数

- TextPart: default import → named import
- MaterialCard: 使用 formatDateLabel 显示今天/昨天/日期
- 清理旧测试文件,新增 ResourceTable 测试
This commit is contained in:
2026-06-03 21:08:00 +08:00
parent 83cc28fe1b
commit eb93de52d8
17 changed files with 252 additions and 1177 deletions

View File

@@ -3,6 +3,23 @@ export function formatCountdown(seconds: number): string {
return `${Math.floor(seconds / 60)}${seconds % 60}`;
}
export function formatDateLabel(dateStr: string, now: Date = new Date()): string {
const date = new Date(dateStr);
if (Number.isNaN(date.getTime())) return "—";
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const yesterday = new Date(today.getTime() - 86_400_000);
const dateDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
if (dateDay.getTime() >= today.getTime()) return "今天";
if (dateDay.getTime() >= yesterday.getTime()) return "昨天";
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
export function formatDurationUnit(ms: null | number): { suffix: string; value: number } {
if (ms === null) return { suffix: "", value: 0 };
if (ms < 60000) return { suffix: "秒", value: roundToOne(ms / 1000) };