refactor: streamline date conversion logic in repository implementations
This commit is contained in:
@@ -7,7 +7,6 @@ class GetStartedBackground extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.white,
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:firebase_auth/firebase_auth.dart' as firebase;
|
|||||||
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||||
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||||
import 'package:krow_domain/krow_domain.dart';
|
import 'package:krow_domain/krow_domain.dart';
|
||||||
|
import 'package:krow_core/core.dart';
|
||||||
import '../../domain/repositories/clock_in_repository_interface.dart';
|
import '../../domain/repositories/clock_in_repository_interface.dart';
|
||||||
|
|
||||||
/// Implementation of [ClockInRepositoryInterface] using Firebase Data Connect.
|
/// Implementation of [ClockInRepositoryInterface] using Firebase Data Connect.
|
||||||
@@ -30,18 +31,35 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
|||||||
/// Helper to convert Data Connect Timestamp to DateTime
|
/// Helper to convert Data Connect Timestamp to DateTime
|
||||||
DateTime? _toDateTime(dynamic t) {
|
DateTime? _toDateTime(dynamic t) {
|
||||||
if (t == null) return null;
|
if (t == null) return null;
|
||||||
// Attempt to use toJson assuming it matches the generated code's expectation of String
|
DateTime? dt;
|
||||||
try {
|
if (t is DateTime) {
|
||||||
// If t has toDate (e.g. cloud_firestore), usage would be t.toDate()
|
dt = t;
|
||||||
// But here we rely on toJson or toString
|
} else if (t is String) {
|
||||||
return DateTime.tryParse(t.toJson() as String);
|
dt = DateTime.tryParse(t);
|
||||||
} catch (_) {
|
} else {
|
||||||
try {
|
try {
|
||||||
return DateTime.tryParse(t.toString());
|
if (t is Timestamp) {
|
||||||
} catch (e) {
|
dt = t.toDateTime();
|
||||||
return null;
|
}
|
||||||
}
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper to create Timestamp from DateTime
|
/// Helper to create Timestamp from DateTime
|
||||||
|
|||||||
@@ -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_data_connect/src/session/staff_session_store.dart';
|
||||||
import 'package:krow_domain/krow_domain.dart';
|
import 'package:krow_domain/krow_domain.dart';
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:krow_core/core.dart';
|
||||||
import '../../domain/repositories/payments_repository.dart';
|
import '../../domain/repositories/payments_repository.dart';
|
||||||
|
|
||||||
class PaymentsRepositoryImpl implements PaymentsRepository {
|
class PaymentsRepositoryImpl implements PaymentsRepository {
|
||||||
@@ -46,25 +47,34 @@ class PaymentsRepositoryImpl implements PaymentsRepository {
|
|||||||
/// Helper to convert Data Connect Timestamp to DateTime
|
/// Helper to convert Data Connect Timestamp to DateTime
|
||||||
DateTime? _toDateTime(dynamic t) {
|
DateTime? _toDateTime(dynamic t) {
|
||||||
if (t == null) return null;
|
if (t == null) return null;
|
||||||
if (t is DateTime) return t;
|
DateTime? dt;
|
||||||
if (t is String) return DateTime.tryParse(t);
|
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 {
|
try {
|
||||||
if (t is Timestamp) {
|
if (dt == null && t.runtimeType.toString().contains('Timestamp')) {
|
||||||
return t.toDateTime();
|
dt = (t as dynamic).toDate();
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} 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) {
|
||||||
|
dt = DateTime.tryParse(t.toString());
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dt != null) {
|
||||||
|
return DateTimeUtils.toDeviceTime(dt);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user