From 0ef7731db3f24cc63e1ab1af2b1bf1f4b4455c62 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Thu, 31 Oct 2024 16:27:03 +0545 Subject: [PATCH] fix: Handle integer expiry date #3038 --- lib/app/shared/date/date.dart | 11 +++++++++++ .../detail/cubit/credential_details_cubit.dart | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/app/shared/date/date.dart b/lib/app/shared/date/date.dart index ea787ddea..7d0d0da5c 100644 --- a/lib/app/shared/date/date.dart +++ b/lib/app/shared/date/date.dart @@ -111,4 +111,15 @@ class UiDate { return null; } } + + static DateTime parseExpirationDate(String input) { + if (RegExp(r'^\d+$').hasMatch(input)) { + // numeric date string + final int timestamp = int.parse(input); + return DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + } else { + // ISO 8601 formatted date string + return DateTime.parse(input); + } + } } diff --git a/lib/dashboard/home/tab_bar/credentials/detail/cubit/credential_details_cubit.dart b/lib/dashboard/home/tab_bar/credentials/detail/cubit/credential_details_cubit.dart index fb9f83067..f11034bf5 100644 --- a/lib/dashboard/home/tab_bar/credentials/detail/cubit/credential_details_cubit.dart +++ b/lib/dashboard/home/tab_bar/credentials/detail/cubit/credential_details_cubit.dart @@ -90,7 +90,7 @@ class CredentialDetailsCubit extends Cubit { if (item.expirationDate != null) { final DateTime dateTimeExpirationDate = - DateTime.parse(item.expirationDate!); + UiDate.parseExpirationDate(item.expirationDate!); if (!dateTimeExpirationDate.isAfter(DateTime.now())) { emit( state.copyWith(