Feat: fixed string data type to timestamp for DepartureTime and ArrivalTime fields

This commit is contained in:
orangdeso 2025-04-16 17:35:32 +07:00
parent 3c635dd951
commit f395d6c4d2
3 changed files with 91 additions and 3 deletions

View File

@ -0,0 +1,56 @@
import 'package:intl/intl.dart';
class DateFormatterHelper {
static String formatFlightTime(dynamic timeValue) {
if (timeValue == null) return "";
if (timeValue is int) {
return DateFormat.jm().format(DateTime.fromMillisecondsSinceEpoch(timeValue));
} else if (timeValue is String) {
return timeValue;
}
return "";
}
static String formatFlightDate(dynamic timeValue) {
if (timeValue == null) return "";
if (timeValue is int) {
return DateFormat("EEE, d MMM").format(DateTime.fromMillisecondsSinceEpoch(timeValue));
}
return "";
}
static String calculateFlightDuration(dynamic departureTime, dynamic arrivalTime) {
if (departureTime == null || arrivalTime == null) return "";
DateTime? departure;
DateTime? arrival;
if (departureTime is int) {
departure = DateTime.fromMillisecondsSinceEpoch(departureTime);
}
if (arrivalTime is int) {
arrival = DateTime.fromMillisecondsSinceEpoch(arrivalTime);
}
if (departure == null || arrival == null) return "";
final difference = arrival.difference(departure);
final hours = difference.inHours;
final minutes = difference.inMinutes % 60;
if (hours > 0) {
if (minutes > 0) {
return "${hours}j ${minutes}m";
} else {
return "${hours}j";
}
} else {
return "${minutes}m";
}
}
}

View File

@ -0,0 +1,32 @@
class MapHelper {
static dynamic getNestedValue(dynamic data, List<String> keys, dynamic defaultValue) {
if (data == null) return defaultValue;
dynamic currentData = data;
for (String key in keys) {
if (currentData is Map && currentData.containsKey(key)) {
currentData = currentData[key];
} else {
return defaultValue;
}
}
return currentData ?? defaultValue;
}
static bool hasNestedPath(dynamic data, List<String> keys) {
if (data == null) return false;
dynamic currentData = data;
for (String key in keys) {
if (currentData is Map && currentData.containsKey(key)) {
currentData = currentData[key];
} else {
return false;
}
}
return true;
}
}

View File

@ -266,7 +266,7 @@ class _TicketBookingStep4ScreenState extends State<TicketBookingStep4Screen> {
// Persiapkan data expiry time
final DateTime currentTime = DateTime.now();
final DateTime expiryTime = currentTime.add(Duration(days: 1));
final DateTime expiryTime = currentTime.add(Duration(seconds: 20));
// Persiapkan data bandara
final bandaraData = {
@ -292,8 +292,8 @@ class _TicketBookingStep4ScreenState extends State<TicketBookingStep4Screen> {
'cityArrival': flightData?.cityArrival,
'codeDeparture': flightData?.codeDeparture,
'codeArrival': flightData?.codeArrival,
'departureTime': departureTime,
'arrivalTime': arrivalTime,
'departureTime': flightData?.departureTime.millisecondsSinceEpoch,
'arrivalTime': flightData?.arrivalTime.millisecondsSinceEpoch,
'flightClass': flightData?.flightClass,
'transitAirplane': flightData?.transitAirplane,
'stop': flightData?.stop,