From 28a3206aba1b41ebde2c67af33897c8dd659706f Mon Sep 17 00:00:00 2001 From: Jovan Ssebaggala Date: Wed, 12 Jun 2024 12:59:38 +0300 Subject: [PATCH] display correct locale date in view mode --- src/components/inputs/date/date.component.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/inputs/date/date.component.tsx b/src/components/inputs/date/date.component.tsx index cc7832be5..413024257 100644 --- a/src/components/inputs/date/date.component.tsx +++ b/src/components/inputs/date/date.component.tsx @@ -12,7 +12,7 @@ import FieldValueView from '../../value/view/field-value-view.component'; import RequiredFieldLabel from '../../required-field-label/required-field-label.component'; import styles from './date.scss'; import { useFieldValidationResults } from '../../../hooks/useFieldValidationResults'; -import { OpenmrsDatePicker } from '@openmrs/esm-framework'; +import { OpenmrsDatePicker, formatDate, formatTime } from '@openmrs/esm-framework'; const locale = window.i18next.language == 'en' ? 'en-GB' : window.i18next.language; const dateFormatter = new Intl.DateTimeFormat(locale); @@ -181,9 +181,9 @@ const DateField: React.FC = ({ question, onChange, handler, prev }; function getDisplay(date: Date, rendering: string) { - const dateString = date.toLocaleDateString(window.navigator.language); + const dateString = formatDate(date); if (rendering == 'datetime') { - return `${dateString} ${date.toLocaleTimeString()}`; + return `${dateString} ${formatTime(date)}`; } return dateString; }