Skip to content

Commit f8229df

Browse files
committed
fix(ui-date-input): correctly format the DateInput2 placeholder in every timezone
1 parent b1bc451 commit f8229df

File tree

1 file changed

+8
-5
lines changed
  • packages/ui-date-input/src/DateInput2

1 file changed

+8
-5
lines changed

packages/ui-date-input/src/DateInput2/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ const DateInput2 = forwardRef(
224224
return date ? [formatDate(date), date.toISOString()] : ['', '']
225225
}
226226

227-
const formatDate = (date: Date): string => {
227+
const formatDate = (
228+
date: Date,
229+
timeZone: string = getTimezone()
230+
): string => {
228231
// use formatter function if provided
229232
if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
230233
return dateFormat.formatter(date)
@@ -233,16 +236,16 @@ const DateInput2 = forwardRef(
233236
return date.toLocaleDateString(
234237
typeof dateFormat === 'string' ? dateFormat : getLocale(),
235238
{
236-
timeZone: getTimezone(),
239+
timeZone,
237240
calendar: 'gregory',
238241
numberingSystem: 'latn'
239242
}
240243
)
241244
}
242245

243-
const getDateFromatHint = () => {
246+
const getDateFormatHint = () => {
244247
const exampleDate = new Date('2024-09-01')
245-
const formattedDate = formatDate(exampleDate)
248+
const formattedDate = formatDate(exampleDate, 'UTC') // exampleDate is in UTC so format it as such
246249

247250
// Create a regular expression to find the exact match of the number
248251
const regex = (n: string) => {
@@ -300,7 +303,7 @@ const DateInput2 = forwardRef(
300303
onBlur={handleBlur}
301304
isRequired={isRequired}
302305
value={value}
303-
placeholder={placeholder ?? getDateFromatHint()}
306+
placeholder={placeholder ?? getDateFormatHint()}
304307
width={width}
305308
display={isInline ? 'inline-block' : 'block'}
306309
messages={inputMessages}

0 commit comments

Comments
 (0)