Files
cozsweet-frontend-nextjs/src/utils/date.ts
T
admin 6e51cb7d16 Refactor: Remove original Dart references from comments across multiple files
- Updated comments in various components, schemas, and repositories to remove references to original Dart files.
- Ensured consistency in documentation while maintaining the context of the code.
2026-06-29 11:31:21 +08:00

41 lines
1.1 KiB
TypeScript

/**
* 日期工具
*
*
*
* 业务侧用 `formatDate(date)` 生成聊天时间戳,`todayString()` 用于每日配额 key。
*/
/** 格式:`HH:mm`(与 Dart 端 `formatDate` 一致) */
export function formatDate(date: Date = new Date()): string {
const hh = String(date.getHours()).padStart(2, "0");
const mm = String(date.getMinutes()).padStart(2, "0");
return `${hh}:${mm}`;
}
/** 格式:`YYYY-MM-DD`,用于每日配额 key。 */
export function todayString(date: Date = new Date()): string {
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");
const d = String(date.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
}
/** 格式:人类可读的日期(`MMM D, YYYY`)。 */
export function formatHumanDate(date: Date = new Date()): string {
return date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
});
}
/** 同一日期(忽略时分秒) */
export function isSameDay(a: Date, b: Date): boolean {
return (
a.getFullYear() === b.getFullYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
);
}