Skip to content

Commit 4734f96

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

File tree

1 file changed

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

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,21 @@ const DateInput2 = ({
214214
return date ? [formatDate(date), date.toISOString()] : ['', '']
215215
}
216216

217-
const formatDate = (date: Date): string => {
217+
const formatDate = (date: Date, timeZone: string = getTimezone()): string => {
218218
// use formatter function if provided
219219
if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
220220
return dateFormat.formatter(date)
221221
}
222222
// if dateFormat set to a locale, use that, otherwise default to the user's locale
223223
return date.toLocaleDateString(
224224
typeof dateFormat === 'string' ? dateFormat : getLocale(),
225-
{ timeZone: getTimezone(), calendar: 'gregory', numberingSystem: 'latn' }
225+
{ timeZone, calendar: 'gregory', numberingSystem: 'latn' }
226226
)
227227
}
228228

229229
const getDateFromatHint = () => {
230230
const exampleDate = new Date('2024-09-01')
231-
const formattedDate = formatDate(exampleDate)
231+
const formattedDate = formatDate(exampleDate, 'UTC') // exampleDate is in UTC so format it as such
232232

233233
// Create a regular expression to find the exact match of the number
234234
const regex = (n: string) => {

0 commit comments

Comments
 (0)