I'm looking to make a function which is checking if a value in my structured array is well included between a past date and today then if yes did the action.
I've trying do something like this :
func GetSpecificTotalTimeFromDate(inArray: Array<Flight>, ofTime: KeyPath<Flight, String>, numberOfLastMonth: Int) -> String{
var initDate = Calendar.current.date(byAdding: .month, value: numberOfLastMonth, to: Date())!
let endDate = Date()
var specificTotalTime: String = ""
var specificTimeInt: Int = 0
for i in inArray{
let isFindBetween = (initDate ... endDate).contains(i[keyPath: .date])
guard initDate < endDate else {
if isFindBetween == true {
let stringValueToAdd: String = i[keyPath: ofTime]
specificTimeInt = specificTimeInt + hhmmToMinutes(stringValueToAdd)
}
}
}
specificTotalTime = minutesToHourMinute(specificTimeInt)
return specificTotalTime
}
I'm trying to use, as I could find on other post, the .contains parameters but I haven't found some documentation about it and it seems to not working like this...
Edit :
To be more precise I send to my function a structured array where I've got a date as date format saving via a date pickers. And I have 3 different type of duration which are set by user under this format : HH:MM.
Now with my function I would like to be able to work, in an array set in parameter 1 under the index passed via parameter 2, only where the date index on my array is located between Today's date (endDate) and Today minus the number of month passed in the third parameter in my function (initDate).
After that if the date is between this two date I save the String value in the specified index (Parameter 2) int a variable (stringValueToAdd). Then I convert it from string "HH:MM" into an Int of total sum in minute with my function : hhmmToMinutes() and add this result into a variable specificTimeInt.
I do this on all entry of my array where the date match with my filter.
then I return a String from specificTimeInt formatted as HH:MM by my function minuteToHoursMinute()
Hope to be more precise with that !
thanks