         print("lol-location \(error.localizedDescription)")
     }
 }
+
+
+private extension Date {
+    func isAfterDate(date: Date) -> Bool {
+        return NSDate(timeIntervalSinceNow: self.timeIntervalSinceNow).earlierDate(date) == date
+    }
+
+    func isBeforeDate(date: Date) -> Bool {
+        return NSDate(timeIntervalSinceNow: self.timeIntervalSinceNow).earlierDate(date) == self
+    }
+}
+

                once = true
            }
            
            #if (arch(i386) || arch(x86_64))
                let geocoder = CLGeocoder()
                geocoder.reverseGeocodeLocation(location) { placemarks, error in


    var sunriseSet: EDSunriseSet? {
        didSet {
            setSunriseSetTimes()
        }
    }

    private func setSunriseSetTimes() {
        let today = Date()

        guard let sunriseSet = self.sunriseSet else {
            return self.sunriseSetTimesLabel.text = nil
        }

        sunriseSet.calculateSunriseSunset(today)

        guard var sunrise = sunriseSet.localSunrise(),
            var sunset = sunriseSet.localSunset(),
            let calendar = NSCalendar(identifier: NSCalendar.Identifier.gregorian) else {
                return self.sunriseSetTimesLabel.text = nil
        }

        sunrise.day = calendar.component(NSCalendar.Unit.day, from: today)
        sunrise.month = calendar.component(NSCalendar.Unit.month, from: today)
        sunrise.year = calendar.component(NSCalendar.Unit.year, from: today)

        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "h:mm a"

        if let sunriseTime = calendar.date(from: sunrise),
            sunriseTime.isAfterDate(date: today) {
            let timeAsString = dateFormatter.string(from: sunriseTime)
            return self.sunriseSetTimesLabel.text = "Sunrise is at \(timeAsString) today"
        }

        sunset.day = calendar.component(NSCalendar.Unit.day, from: today)
        sunset.month = calendar.component(NSCalendar.Unit.month, from: today)
        sunset.year = calendar.component(NSCalendar.Unit.year, from: today)

        if let sunsetTime = calendar.date(from: sunset),
            sunsetTime.isAfterDate(date: today) {
            let timeAsString = dateFormatter.string(from: sunsetTime)
            return self.sunriseSetTimesLabel.text = "Sunset is at \(timeAsString) today"
        }

        let tomorrow = today.addingTimeInterval(ONE_DAY)
        sunriseSet.calculateSunriseSunset(tomorrow)
        if let tomorrowSunrise = sunriseSet.localSunrise(),
            let tomorrowSunriseTime = calendar.date(from: tomorrowSunrise) {
            let timeAsString = dateFormatter.string(from: tomorrowSunriseTime)
            self.sunriseSetTimesLabel.text = "Sunrise is at \(timeAsString) tomorrow"
        } else {
            self.sunriseSetTimesLabel.text = nil
        }
    }

