SwiftDate icon indicating copy to clipboard operation
SwiftDate copied to clipboard

When sorting a TimePeriodCollection, .ascending and .descending seems to have the same order

Open nickvelloff opened this issue 7 years ago • 0 comments

I could very well just be doing this incorrectly, but it appears that .ascending and .descending are not respecting the start values in the TimePeriodCollection. It does sort, yet for me seems to ignore these options.

And thanks for the awesome library.

private func nextAvailableDate(now: DateInRegion) {
        
        let mondayStart = now.dateAt(.nextWeekday(.monday)).dateBySet(hour: 17, min: nil, secs: nil)
        let mondayEnd = now.dateAt(.nextWeekday(.monday)).dateBySet(hour: 20, min: nil, secs: nil)
        let monday = TimePeriod(start: mondayStart , end: mondayEnd)
        
        let tuesdayStart = now.dateAt(.nextWeekday(.tuesday)).dateBySet(hour: 17, min: nil, secs: nil)
        let tuesdayEnd = now.dateAt(.nextWeekday(.tuesday)).dateBySet(hour: 20, min: nil, secs: nil)
        let tuesday = TimePeriod(start: tuesdayStart , end: tuesdayEnd)
        
        let wednesdayStart = now.dateAt(.nextWeekday(.wednesday)).dateBySet(hour: 17, min: nil, secs: nil)
        let wednesdayEnd = now.dateAt(.nextWeekday(.wednesday)).dateBySet(hour: 20, min: nil, secs: nil)
        let wednesday = TimePeriod(start: wednesdayStart , end: wednesdayEnd)
        
        let thursdayStart = now.dateAt(.nextWeekday(.thursday)).dateBySet(hour: 17, min: nil, secs: nil)
        let thursdayEnd = now.dateAt(.nextWeekday(.thursday)).dateBySet(hour: 20, min: nil, secs: nil)
        let thursday = TimePeriod(start: thursdayStart , end: thursdayEnd)
        
        let fridayStart = now.dateAt(.nextWeekday(.friday)).dateBySet(hour: 17, min: nil, secs: nil)
        let fridayEnd = now.dateAt(.nextWeekday(.friday)).dateBySet(hour: 20, min: nil, secs: nil)
        let friday = TimePeriod(start: fridayStart , end: fridayEnd)
        
        let saturdayStart = now.dateAt(.nextWeekday(.saturday)).dateBySet(hour: 14, min: nil, secs: nil)
        let saturdayEnd = now.dateAt(.nextWeekday(.saturday)).dateBySet(hour: 23, min: 59, secs: 59)
        let saturday = TimePeriod(start: saturdayStart , end: saturdayEnd)
        
        let sundayStart = now.dateAt(.nextWeekday(.sunday)).dateBySet(hour: 17, min: nil, secs: nil)
        let sundayEnd = now.dateAt(.nextWeekday(.sunday)).dateBySet(hour: 20, min: 59, secs: 59)
        let sunday = TimePeriod(start: sundayStart , end: sundayEnd)
        
        let collection = TimePeriodCollection()
        collection.append([monday, tuesday, wednesday, thursday, friday, saturday, sunday])
        
        let sortedAscending = collection.sorted(by: .start(.ascending))
        let sortedDescending = collection.sorted(by: .start(.descending))

        // order of sortedAscending and sortedDescending is the same
    }

nickvelloff avatar Oct 08 '18 07:10 nickvelloff