Spaces:
Sleeping
Sleeping
Download apps/dsa-web/src/utils/format.ts from derrickliu/stock_analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/derrickliu/stock_analysis/resolve/main/apps/dsa-web/src/utils/format.ts
- Command line
-
hf download hf://spaces/derrickliu/stock_analysis/apps/dsa-web/src/utils/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/derrickliu/stock_analysis/resolve/main/apps/dsa-web/src/utils/format.ts
1.87 kB
| export const formatDateTime = (value?: string): string => { | |
| if (!value) return 'โ'; | |
| const date = new Date(value); | |
| if (Number.isNaN(date.getTime())) return value; | |
| return new Intl.DateTimeFormat('zh-CN', { | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| }).format(date); | |
| }; | |
| export const formatDate = (value?: string): string => { | |
| if (!value) return 'โ'; | |
| const date = new Date(value); | |
| if (Number.isNaN(date.getTime())) return value; | |
| return new Intl.DateTimeFormat('zh-CN', { | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit', | |
| }).format(date); | |
| }; | |
| export const toDateInputValue = (date: Date): string => { | |
| const year = date.getFullYear(); | |
| const month = `${date.getMonth() + 1}`.padStart(2, '0'); | |
| const day = `${date.getDate()}`.padStart(2, '0'); | |
| return `${year}-${month}-${day}`; | |
| }; | |
| /** | |
| * Returns the date N days ago as YYYY-MM-DD in Asia/Shanghai timezone. | |
| * Consistent with getTodayInShanghai() so both ends of the date range | |
| * are expressed in the same timezone as the backend. | |
| */ | |
| export const getRecentStartDate = (days: number): string => { | |
| const date = new Date(); | |
| date.setDate(date.getDate() - days); | |
| return new Intl.DateTimeFormat('en-CA', { timeZone: 'Asia/Shanghai' }).format(date); | |
| }; | |
| /** | |
| * Returns today's date as YYYY-MM-DD in Asia/Shanghai timezone. | |
| * Use this instead of browser-local date to stay consistent with the backend, | |
| * which stores and filters timestamps in server local time (Asia/Shanghai). | |
| */ | |
| export const getTodayInShanghai = (): string => | |
| new Intl.DateTimeFormat('en-CA', { timeZone: 'Asia/Shanghai' }).format(new Date()); | |
| export const formatReportType = (value?: string): string => { | |
| if (!value) return 'โ'; | |
| if (value === 'simple') return 'ๆฎ้'; | |
| if (value === 'detailed') return 'ๆ ๅ'; | |
| return value; | |
| }; | |