refactor: streamline date conversion logic in repository implementations
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||
import 'package:krow_data_connect/src/session/staff_session_store.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import '../../domain/repositories/payments_repository.dart';
|
||||
|
||||
class PaymentsRepositoryImpl implements PaymentsRepository {
|
||||
@@ -46,25 +47,34 @@ class PaymentsRepositoryImpl implements PaymentsRepository {
|
||||
/// Helper to convert Data Connect Timestamp to DateTime
|
||||
DateTime? _toDateTime(dynamic t) {
|
||||
if (t == null) return null;
|
||||
if (t is DateTime) return t;
|
||||
if (t is String) return DateTime.tryParse(t);
|
||||
DateTime? dt;
|
||||
if (t is DateTime) {
|
||||
dt = t;
|
||||
} else if (t is String) {
|
||||
dt = DateTime.tryParse(t);
|
||||
} else {
|
||||
try {
|
||||
if (t is Timestamp) {
|
||||
dt = t.toDateTime();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
if (t is Timestamp) {
|
||||
return t.toDateTime();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
if (t.runtimeType.toString().contains('Timestamp')) {
|
||||
return (t as dynamic).toDate();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
return DateTime.tryParse(t.toString());
|
||||
} catch (_) {}
|
||||
try {
|
||||
if (dt == null && t.runtimeType.toString().contains('Timestamp')) {
|
||||
dt = (t as dynamic).toDate();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
if (dt == null) {
|
||||
dt = DateTime.tryParse(t.toString());
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
if (dt != null) {
|
||||
return DateTimeUtils.toDeviceTime(dt);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user