fix(workspace): 使用本地日期生成今日日报
This commit is contained in:
12
apps/web/lib/format.test.ts
Normal file
12
apps/web/lib/format.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { formatLocalDate } from './format';
|
||||
|
||||
test('formatLocalDate formats a local calendar date as YYYY-MM-DD', () => {
|
||||
assert.equal(formatLocalDate(new Date(2026, 5, 26, 23, 59)), '2026-06-26');
|
||||
});
|
||||
|
||||
test('formatLocalDate pads month and day', () => {
|
||||
assert.equal(formatLocalDate(new Date(2026, 0, 2, 8, 5)), '2026-01-02');
|
||||
});
|
||||
@@ -34,6 +34,13 @@ export function formatDate(iso?: string | null): string {
|
||||
/**
|
||||
* 格式化为 MM-DD HH:mm(紧凑版,本地时区)
|
||||
*/
|
||||
export function formatLocalDate(date: Date = new Date()): string {
|
||||
const yyyy = date.getFullYear();
|
||||
const mm = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const dd = String(date.getDate()).padStart(2, '0');
|
||||
return `${yyyy}-${mm}-${dd}`;
|
||||
}
|
||||
|
||||
export function formatDateTimeShort(iso?: string | null): string {
|
||||
if (!iso) return '-';
|
||||
const d = new Date(iso);
|
||||
|
||||
Reference in New Issue
Block a user