-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix: time format issue in datepicker mask #16922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4ab4284
0166f78
9d9ab80
9ecda5e
39f9644
18e42ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { DateFormat } from '@/localization/constants/DateFormat'; | ||
| import { detectDateFormat } from '@/localization/utils/detection/detectDateFormat'; | ||
|
|
||
| export const resolveDateFormat = (dateFormat: DateFormat): DateFormat => { | ||
| if (dateFormat === DateFormat.SYSTEM) { | ||
| const detectedFormat = detectDateFormat(); | ||
| return DateFormat[detectedFormat]; | ||
| } | ||
|
|
||
| return dateFormat; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { TimeFormat } from '@/localization/constants/TimeFormat'; | ||
| import { detectTimeFormat } from '@/localization/utils/detection/detectTimeFormat'; | ||
|
|
||
| export const resolveTimeFormat = (timeFormat: TimeFormat): TimeFormat => { | ||
vasu1303 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (timeFormat === TimeFormat.SYSTEM) { | ||
| const detectedFormat = detectTimeFormat(); | ||
| return TimeFormat[detectedFormat]; | ||
| } | ||
|
|
||
| return timeFormat; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| import { useDateTimeFormat } from '@/localization/hooks/useDateTimeFormat'; | ||
| import { format } from 'date-fns'; | ||
| import { format, isValid } from 'date-fns'; | ||
| import { getDateTimeFormatStringFoDatePickerInputMask } from '~/utils/date-utils'; | ||
|
|
||
| export const useParseJSDateToIMaskDateTimeInputString = () => { | ||
| const { dateFormat } = useDateTimeFormat(); | ||
| const { dateFormat, timeFormat } = useDateTimeFormat(); | ||
|
|
||
| const parseJSDateToDateTimeInputString = (date: Date) => { | ||
| const parsingFormat = | ||
| getDateTimeFormatStringFoDatePickerInputMask(dateFormat); | ||
| if (!date || !isValid(date)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't bring validation with the Date object, as we're trying to avoid its usage. Prefer using Temporal. |
||
| return ''; | ||
| } | ||
|
|
||
| const parsingFormat = getDateTimeFormatStringFoDatePickerInputMask({ | ||
| dateFormat, | ||
| timeFormat, | ||
| }); | ||
|
|
||
| return format(date, parsingFormat); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import { TIME_MASK } from '@/ui/input/components/internal/date/constants/TimeMask'; | ||
|
|
||
| import { type DateFormat } from '@/localization/constants/DateFormat'; | ||
| import { type TimeFormat } from '@/localization/constants/TimeFormat'; | ||
| import { getDateMask } from './getDateMask'; | ||
| import { getTimeMask } from './getTimeMask'; | ||
|
|
||
| export const getDateTimeMask = (dateFormat: DateFormat): string => { | ||
| return `${getDateMask(dateFormat)} ${TIME_MASK}`; | ||
| export const getDateTimeMask = ({ | ||
| dateFormat, | ||
| timeFormat, | ||
| }: { | ||
| dateFormat: DateFormat; | ||
| timeFormat: TimeFormat; | ||
| }): string => { | ||
| return `${getDateMask(dateFormat)} ${getTimeMask(timeFormat)}`; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { TimeFormat } from '@/localization/constants/TimeFormat'; | ||
| import { IMask } from 'react-imask'; | ||
|
|
||
| export const getTimeBlocks = (timeFormat: TimeFormat) => { | ||
| const isHour12 = timeFormat === TimeFormat.HOUR_12; | ||
|
|
||
| return { | ||
| HH: { | ||
| mask: IMask.MaskedRange, | ||
| from: isHour12 ? 1 : 0, | ||
| to: isHour12 ? 12 : 23, | ||
| maxLength: 2, | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The time input's AM/PM validation is case-sensitive, expecting Suggested FixTo fix the case-sensitivity issue, either update the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| mm: { | ||
| mask: IMask.MaskedRange, | ||
| from: 0, | ||
| to: 59, | ||
| maxLength: 2, | ||
| }, | ||
| ...(isHour12 && { | ||
| aa: { | ||
| mask: IMask.MaskedEnum, | ||
| enum: ['AM', 'PM'], | ||
| }, | ||
| }), | ||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { TimeFormat } from '@/localization/constants/TimeFormat'; | ||
|
|
||
| export const getTimeMask = (timeFormat: TimeFormat): string => { | ||
| return timeFormat === TimeFormat.HOUR_12 ? 'HH`:`mm` `aa' : 'HH`:`mm'; | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.