                 }
 
                 var dif = s - t
-                if dif < 0 {
+                if dif <= 0 {
                     dif += session.cycle!.int64Value
                 }
                 if !session.isInPeriod(time: time + dif) {

    }

    func nextChange(time: Int64) -> Int64 {
        recursiveCount = 0

        let currentSession = findCurrentSession(time: time)
        if currentSession != nil {
            let nearestException = findNearest(exceptions, nil, time)

            }

            if currentException != nil {
                var exRemaining = currentException!.remaining(time: time)
                for exception in exceptions! {
                    if isInSession(exception, time + exRemaining) {
                        exRemaining += exception.remaining(time: time + exRemaining)
                    }
                }
                if findCurrentSession(time: time + exRemaining) != nil {
                    return exRemaining
                }
            }
        }

        return findNearest(sessions, exceptions, time)
    }

    func findNearest(_ sessions: [Session]?, _ exceptions: [Session]?, _ time: Int64) -> Int64 {
        var nearestTime = Int64.max
