feat: enhance date parsing for shift start time in CommuteTracker
This commit is contained in:
@@ -68,11 +68,18 @@ class _CommuteTrackerState extends State<CommuteTracker> {
|
||||
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<CommuteTracker> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user