fix(workspace): 使用本地日期生成今日日报
This commit is contained in:
@@ -21,7 +21,7 @@ import { TestCaseDetailDrawer } from '@/components/test-case/TestCaseDetailDrawe
|
||||
import { BugDetailDrawer } from '@/components/bug/BugDetailDrawer';
|
||||
import { BugCreateModal } from '@/components/bug/BugCreateModal';
|
||||
import { DEV_TASK_STATUS_LABEL, DEV_TASK_STATUS_COLOR, getEstimateHours, getActualHours } from '@/lib/dev-task';
|
||||
import { formatDateTime } from '@/lib/format';
|
||||
import { formatDateTime, formatLocalDate } from '@/lib/format';
|
||||
import { formatShortTime, formatWorkHours } from '@/lib/work-hours';
|
||||
import { TEST_CASE_STATUS_LABEL, TEST_CASE_STATUS_COLOR } from '@/lib/test-case';
|
||||
import { BUG_STATUS_LABEL, BUG_STATUS_COLOR, BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug';
|
||||
@@ -118,7 +118,7 @@ export default function WorkspacePage() {
|
||||
return items.sort((a, b) => (a.completed !== b.completed ? (a.completed ? 1 : -1) : 0));
|
||||
}, [workItems, activeTab, showCompleted, selectedVersionId]);
|
||||
|
||||
const today = useMemo(() => new Date().toISOString().slice(0, 10), []);
|
||||
const today = useMemo(() => formatLocalDate(), []);
|
||||
|
||||
const dailyReport = useMemo(() =>
|
||||
getWorkspaceDailyReport({
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Plus, Trash2 } from 'lucide-react';
|
||||
import { useTaskWorklogStore } from '@/stores/useTaskWorklogStore';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
import { getTaskWorklogs } from '@/lib/task-worklog';
|
||||
import { formatLocalDate } from '@/lib/format';
|
||||
|
||||
interface Props {
|
||||
taskId: string;
|
||||
@@ -17,7 +18,7 @@ export function WorklogPanel({ taskId }: Props) {
|
||||
const taskLogs = getTaskWorklogs(worklogs, taskId);
|
||||
const totalHours = taskLogs.reduce((sum, w) => sum + w.hours, 0);
|
||||
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const today = formatLocalDate();
|
||||
const [date, setDate] = useState(today);
|
||||
const [hours, setHours] = useState<number>(1);
|
||||
const [workContent, setWorkContent] = useState('');
|
||||
|
||||
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