| setCurrentDate(prev => getDateWithTimezone({ date: prev, timezone })) | setCurrentDate(prev => getDateWithTimezone({ date: prev, timezone })) | ||||
| setSelectedDate(prev => prev ? getDateWithTimezone({ date: prev, timezone }) : undefined) | setSelectedDate(prev => prev ? getDateWithTimezone({ date: prev, timezone }) : undefined) | ||||
| } | } | ||||
| // eslint-disable-next-line react-hooks/exhaustive-deps | |||||
| }, [timezone]) | }, [timezone]) | ||||
| const handleClickTrigger = (e: React.MouseEvent) => { | const handleClickTrigger = (e: React.MouseEvent) => { | ||||
| setView(ViewType.date) | setView(ViewType.date) | ||||
| } | } | ||||
| const timeFormat = needTimePicker ? 'MMMM D, YYYY hh:mm A' : 'MMMM D, YYYY' | |||||
| const timeFormat = needTimePicker ? t('time.dateFormats.displayWithTime') : t('time.dateFormats.display') | |||||
| const displayValue = value?.format(timeFormat) || '' | const displayValue = value?.format(timeFormat) || '' | ||||
| const displayTime = selectedDate?.format('hh:mm A') || '--:-- --' | const displayTime = selectedDate?.format('hh:mm A') || '--:-- --' | ||||
| const placeholderDate = isOpen && selectedDate ? selectedDate.format(timeFormat) : (placeholder || t('time.defaultPlaceholder')) | const placeholderDate = isOpen && selectedDate ? selectedDate.format(timeFormat) : (placeholder || t('time.defaultPlaceholder')) |
| return DEFAULT_OFFSET_STR | return DEFAULT_OFFSET_STR | ||||
| return `UTC${tzItem.name.charAt(0)}${tzItem.name.charAt(2)}` | return `UTC${tzItem.name.charAt(0)}${tzItem.name.charAt(2)}` | ||||
| } | } | ||||
| // Parse date with multiple format support | |||||
| export const parseDateWithFormat = (dateString: string, format?: string): Dayjs | null => { | |||||
| if (!dateString) return null | |||||
| // If format is specified, use it directly | |||||
| if (format) { | |||||
| const parsed = dayjs(dateString, format, true) | |||||
| return parsed.isValid() ? parsed : null | |||||
| } | |||||
| // Try common date formats | |||||
| const formats = [ | |||||
| 'YYYY-MM-DD', // Standard format | |||||
| 'YYYY/MM/DD', // Slash format | |||||
| 'DD-MM-YYYY', // European format | |||||
| 'DD/MM/YYYY', // European slash format | |||||
| 'MM-DD-YYYY', // US format | |||||
| 'MM/DD/YYYY', // US slash format | |||||
| 'YYYY-MM-DDTHH:mm:ss.SSSZ', // ISO format | |||||
| 'YYYY-MM-DDTHH:mm:ssZ', // ISO format (no milliseconds) | |||||
| 'YYYY-MM-DD HH:mm:ss', // Standard datetime format | |||||
| ] | |||||
| for (const fmt of formats) { | |||||
| const parsed = dayjs(dateString, fmt, true) | |||||
| if (parsed.isValid()) | |||||
| return parsed | |||||
| } | |||||
| return null | |||||
| } | |||||
| // Format date output with localization support | |||||
| export const formatDateForOutput = (date: Dayjs, includeTime: boolean = false, locale: string = 'en-US'): string => { | |||||
| if (!date || !date.isValid()) return '' | |||||
| if (includeTime) { | |||||
| // Output format with time | |||||
| return date.format('YYYY-MM-DDTHH:mm:ss.SSSZ') | |||||
| } | |||||
| else { | |||||
| // Date-only output format without timezone | |||||
| return date.format('YYYY-MM-DD') | |||||
| } | |||||
| } |
| import Checkbox from '@/app/components/base/checkbox' | import Checkbox from '@/app/components/base/checkbox' | ||||
| import Select from '@/app/components/base/select' | import Select from '@/app/components/base/select' | ||||
| import { useChatContext } from '@/app/components/base/chat/chat/context' | import { useChatContext } from '@/app/components/base/chat/chat/context' | ||||
| import { formatDateForOutput } from '@/app/components/base/date-and-time-picker/utils/dayjs' | |||||
| enum DATA_FORMAT { | enum DATA_FORMAT { | ||||
| TEXT = 'text', | TEXT = 'text', | ||||
| const getFormValues = (children: any) => { | const getFormValues = (children: any) => { | ||||
| const values: { [key: string]: any } = {} | const values: { [key: string]: any } = {} | ||||
| children.forEach((child: any) => { | children.forEach((child: any) => { | ||||
| if ([SUPPORTED_TAGS.INPUT, SUPPORTED_TAGS.TEXTAREA].includes(child.tagName)) | |||||
| values[child.properties.name] = formValues[child.properties.name] | |||||
| if ([SUPPORTED_TAGS.INPUT, SUPPORTED_TAGS.TEXTAREA].includes(child.tagName)) { | |||||
| let value = formValues[child.properties.name] | |||||
| if (child.tagName === SUPPORTED_TAGS.INPUT | |||||
| && (child.properties.type === SUPPORTED_TYPES.DATE || child.properties.type === SUPPORTED_TYPES.DATETIME)) { | |||||
| if (value && typeof value.format === 'function') { | |||||
| // Format date output consistently | |||||
| const includeTime = child.properties.type === SUPPORTED_TYPES.DATETIME | |||||
| value = formatDateForOutput(value, includeTime) | |||||
| } | |||||
| } | |||||
| values[child.properties.name] = value | |||||
| } | |||||
| }) | }) | ||||
| return values | return values | ||||
| } | } |
| pickTime: 'Pick Time', | pickTime: 'Pick Time', | ||||
| }, | }, | ||||
| defaultPlaceholder: 'Pick a time...', | defaultPlaceholder: 'Pick a time...', | ||||
| // Date format configurations | |||||
| dateFormats: { | |||||
| display: 'MMMM D, YYYY', | |||||
| displayWithTime: 'MMMM D, YYYY hh:mm A', | |||||
| input: 'YYYY-MM-DD', | |||||
| output: 'YYYY-MM-DD', | |||||
| outputWithTime: 'YYYY-MM-DDTHH:mm:ss.SSSZ', | |||||
| }, | |||||
| } | } | ||||
| export default translation | export default translation |
| pickTime: 'ピックタイム', | pickTime: 'ピックタイム', | ||||
| }, | }, | ||||
| defaultPlaceholder: '時間を選んでください...', | defaultPlaceholder: '時間を選んでください...', | ||||
| // Date format configurations | |||||
| dateFormats: { | |||||
| display: 'YYYY年MM月DD日', | |||||
| displayWithTime: 'YYYY年MM月DD日 HH:mm', | |||||
| input: 'YYYY-MM-DD', | |||||
| output: 'YYYY-MM-DD', | |||||
| outputWithTime: 'YYYY-MM-DDTHH:mm:ss.SSSZ', | |||||
| }, | |||||
| } | } | ||||
| export default translation | export default translation |
| pickTime: '选择时间', | pickTime: '选择时间', | ||||
| }, | }, | ||||
| defaultPlaceholder: '请选择时间...', | defaultPlaceholder: '请选择时间...', | ||||
| // Date format configurations | |||||
| dateFormats: { | |||||
| display: 'YYYY年MM月DD日', | |||||
| displayWithTime: 'YYYY年MM月DD日 HH:mm', | |||||
| input: 'YYYY-MM-DD', | |||||
| output: 'YYYY-MM-DD', | |||||
| outputWithTime: 'YYYY-MM-DDTHH:mm:ss.SSSZ', | |||||
| }, | |||||
| } | } | ||||
| export default translation | export default translation |