Skip to content

Commit

Permalink
fix(INJI-416): display dateOfBirth in vcDetails in Android
Browse files Browse the repository at this point in the history
date parsing is causing issue in Android device due to JavaScript VM, thus using date-fns to parse.
  • Loading branch information
KiruthikaJeyashankar committed Oct 4, 2023
1 parent 0ef69b9 commit ef44b30
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/VC/MosipVCItem/MosipVCItemDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {formatDistanceToNow} from 'date-fns';
import {format, formatDistanceToNow, parse} from 'date-fns';
import React from 'react';
import * as DateFnsLocale from 'date-fns/locale';
import {useTranslation} from 'react-i18next';
Expand Down Expand Up @@ -212,11 +212,7 @@ export const MosipVCItemDetails: React.FC<
weight="semibold"
size="smaller"
color={Theme.Colors.Details}>
{new Date(
getLocalizedField(
verifiableCredential?.credentialSubject.dateOfBirth,
),
).toLocaleDateString()}
{formattedDateOfBirth()}
</Text>
</Column>
<Column margin="25 0 0 0">
Expand Down Expand Up @@ -412,6 +408,16 @@ export const MosipVCItemDetails: React.FC<
)}
</Column>
);

function formattedDateOfBirth() {
const dateOfBirth = verifiableCredential?.credentialSubject.dateOfBirth;
const formatString =
dateOfBirth.split('/').length === 1 ? 'yyyy' : 'yyyy/MM/dd';

const parsedDate = parse(dateOfBirth, formatString, new Date());

return format(parsedDate, 'MM/dd/yyyy');
}
};

export interface ExistingMosipVCItemDetailsProps {
Expand Down

0 comments on commit ef44b30

Please sign in to comment.