Skip to content

Commit 5708634

Browse files
committed
tc support
1 parent 1eb8092 commit 5708634

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/app/modules/taskc_details/controllers/taskc_details_controller.dart

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,37 @@ class TaskcDetailsController extends GetxController {
106106
String formatDate(dynamic date) {
107107
if (date == null) return '-';
108108
// If date is epoch seconds as int
109+
bool is24hrFormat = AppSettings.use24HourFormatRx.value;
110+
final pattern =
111+
is24hrFormat ? 'yyyy-MM-dd HH:mm:ss' : 'yyyy-MM-dd hh:mm:ss a';
112+
113+
if (date == null) return '-';
114+
109115
if (date is int) {
110116
try {
111117
final dt = DateTime.fromMillisecondsSinceEpoch(date * 1000);
112-
return DateFormat('yyyy-MM-dd HH:mm:ss').format(dt);
118+
return DateFormat(pattern).format(dt.toLocal());
113119
} catch (e) {
120+
debugPrint('Error formatting epoch date: $e');
114121
return '-';
115122
}
116123
}
124+
117125
if (date is DateTime) {
118-
return DateFormat('yyyy-MM-dd HH:mm:ss').format(date);
126+
try {
127+
return DateFormat(pattern).format(date.toLocal());
128+
} catch (e) {
129+
debugPrint('Error formatting DateTime: $e');
130+
return '-';
131+
}
119132
}
133+
120134
final dateString = date?.toString() ?? '';
121135
if (dateString.isEmpty || dateString == '-') return '-';
136+
122137
try {
123-
DateTime parsedDate = DateTime.parse(dateString);
124-
return DateFormat('yyyy-MM-dd HH:mm:ss').format(parsedDate);
138+
final parsedDate = DateTime.parse(dateString).toLocal();
139+
return DateFormat(pattern).format(parsedDate);
125140
} catch (e) {
126141
debugPrint('Error parsing date: $dateString');
127142
return '-';

0 commit comments

Comments
 (0)