Skip to content

Commit a2055ed

Browse files
authored
Merge pull request #81 from Incomplete-Outputs-Lab/fix/export-preview-local-date
fix: エクスポートプレビューの日付初期値にローカル日付を使用
2 parents 450d25d + 26d90c3 commit a2055ed

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/components/Export/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,25 @@ export function Export() {
1515
const [previewData, setPreviewData] = useState<string>('');
1616
const [isLoadingPreview, setIsLoadingPreview] = useState(false);
1717

18+
// ローカル日付を正しく取得(toISOString は UTC のため、統計ページと同様に getFullYear/getMonth/getDate を使用)
19+
const getInitialDateRange = () => {
20+
const end = new Date();
21+
const start = new Date();
22+
start.setDate(start.getDate() - 7);
23+
const formatLocalDate = (date: Date) => {
24+
const year = date.getFullYear();
25+
const month = String(date.getMonth() + 1).padStart(2, '0');
26+
const day = String(date.getDate()).padStart(2, '0');
27+
return `${year}-${month}-${day}`;
28+
};
29+
return { start: formatLocalDate(start), end: formatLocalDate(end) };
30+
};
31+
const initialRange = getInitialDateRange();
32+
1833
const [config, setConfig] = useState({
1934
channelId: null as number | null,
20-
startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
21-
endDate: new Date().toISOString().split('T')[0],
35+
startDate: initialRange.start,
36+
endDate: initialRange.end,
2237
format: 'tsv' as 'csv' | 'tsv' | 'custom',
2338
aggregation: 'raw' as 'raw' | '1min' | '5min' | '1hour',
2439
customDelimiter: '|',

0 commit comments

Comments
 (0)