diff --git a/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/commute_tracker.dart b/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/commute_tracker.dart index ff3b71a7..f431b285 100644 --- a/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/commute_tracker.dart +++ b/apps/mobile/packages/features/staff/clock_in/lib/src/presentation/widgets/commute_tracker.dart @@ -68,11 +68,18 @@ class _CommuteTrackerState extends State { final now = DateTime.now(); DateTime shiftStart; try { + // Try parsing startTime as full datetime first shiftStart = DateTime.parse(widget.shift!.startTime); } catch (_) { - shiftStart = DateTime.parse( - '${widget.shift!.date} ${widget.shift!.startTime}', - ); + try { + // Try parsing date as full datetime + shiftStart = DateTime.parse(widget.shift!.date); + } catch (_) { + // Fall back to combining date and time + shiftStart = DateTime.parse( + '${widget.shift!.date} ${widget.shift!.startTime}', + ); + } } final hoursUntilShift = shiftStart.difference(now).inHours; final inCommuteWindow = hoursUntilShift <= 24 && hoursUntilShift >= 0; @@ -104,9 +111,21 @@ class _CommuteTrackerState extends State { int _getMinutesUntilShift() { if (widget.shift == null) return 0; final now = DateTime.now(); - final shiftStart = DateTime.parse( - '${widget.shift!.date} ${widget.shift!.startTime}', - ); + DateTime shiftStart; + try { + // Try parsing startTime as full datetime first + shiftStart = DateTime.parse(widget.shift!.startTime); + } catch (_) { + try { + // Try parsing date as full datetime + shiftStart = DateTime.parse(widget.shift!.date); + } catch (_) { + // Fall back to combining date and time + shiftStart = DateTime.parse( + '${widget.shift!.date} ${widget.shift!.startTime}', + ); + } + } return shiftStart.difference(now).inMinutes; }