Skip to content

Commit

Permalink
Merge branch 'funke' into fix/expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatrakazas authored Dec 2, 2024
2 parents 9e4cd44 + 23e7eaa commit 9544e7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/History/HistoryDetailContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const HistoryDetailContent = ({ historyItem }) => {

{/* Render details of the currently selected credential */}
{historyItem[currentSlide - 1] && (
<div className={`pt-5 overflow-y-auto items-center custom-scrollbar ${screenType !== 'mobile' ? 'max-h-[30vh]' : 'max-h-[25vh]'} `}>
<div className={`pt-5 ${screenType !== 'mobile' ? 'overflow-y-auto items-center custom-scrollbar max-h-[30vh]' : ''} `}>
<CredentialInfo credential={historyItem[currentSlide - 1]} display='all' />
</div>
)}
Expand Down
42 changes: 25 additions & 17 deletions src/functions/DateFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@ export function formatDate(value, format = 'datetime') {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
// Regex for simple YYYY-MM-DD format
const simpleDateRegex = /^\d{4}-\d{2}-\d{2}$/;
// Regex for long-form date strings like 'Wed Dec 11 2024 14:46:19 GMT+0200'
const longFormDateRegex = /^[A-Z][a-z]{2} [A-Z][a-z]{2} \d{2} \d{4} \d{2}:\d{2}:\d{2} GMT[+-]\d{4}/;

let date;
if (typeof value == 'number') {
return new Date(value * 1000).toLocaleDateString('en-GB');
}
else if (iso8601Regex.test(value)) {
date = new Date(value);
} else if (simpleDateRegex.test(value)) {
date = new Date(value);
} else {
// Try to parse other formats, such as 'Wed Dec 11 2024 14:46:19 GMT+0200'
try {

if (typeof value === 'number' && value.toString().length === 10) {
// Handle Unix timestamp (seconds) by converting to milliseconds
date = new Date(value * 1000);
} else if (typeof value === 'string') {
if (iso8601Regex.test(value)) {
// Handle ISO 8601 format
date = new Date(value);
} else if (simpleDateRegex.test(value)) {
// Handle YYYY-MM-DD format
date = new Date(value);
if (isNaN(date)) {
// If invalid, return original value
return value;
}
} catch (error) {
// Return original value if parsing fails
} else if (longFormDateRegex.test(value)) {
// Handle long-form date string
date = new Date(value);
} else {
// Non-date strings, including IDs, are returned as-is
return value;
}
} else if (value instanceof Date) {
// Handle Date objects directly
date = value;
} else {
// For unsupported types, return the original value
return value;
}

const options = format === 'datetime'
? { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' }
: { day: '2-digit', month: '2-digit', year: 'numeric' };

return date.toLocaleDateString('en-GB', options);
}
}

0 comments on commit 9544e7b

Please sign in to comment.