Future<int> canWorkerApplyForTheJob(String workerEmail, Job j) async {
int _minutes = 0;
final _jobStartDate =
'${DateTime.parse(j.jobStartDate).toString().split(' ')[0]} 00:00:00.000';
final _jobStartTime =
'${DateTime.parse(j.jobStartDate).toString().split(' ')[0]} ${j.jobStartTime.toString().split(' ')[1]}';
QuerySnapshot _myDoc = await jobsCollection
.where("jobStartDate", isEqualTo: _jobStartDate)
.where("workers", arrayContainsAny: [workerEmail]).getDocuments();
List<DocumentSnapshot> _myDocCount = _myDoc.documents;
_myDocCount.forEach((key) {
final job = key.data;
final jobEndDate = job['jobEndDate'];
final jobEndTime = job['jobEndTime'];
DateTime newJobStartTime = DateTime.parse(
'${j.jobStartDate.split(' ')[0]} ${j.jobStartTime.split(' ')[1]}');
DateTime existingJobStartTime = DateTime.parse(
'${jobEndDate.split(' ')[0]} ${jobEndTime.split(' ')[1]}');
final inMinutes =
newJobStartTime.difference(existingJobStartTime).inMinutes;
if (inMinutes < 480) {
_minutes += 1;
}
});
return _minutes;
}