A swift package that provides NOAA astronomical algorithms for sunrise and sunset times
Swift Shell Ruby Objective-C
Switch branches/tags
Nothing to show
Latest commit 4aa30b3 Apr 19, 2017 Martin Ceperley Adding podspec and license. updating readme
Permalink
Failed to load latest commit information.
Daylight.xcodeproj Adding framework project Apr 20, 2017
Example/DaylightExample
Sources
Tests Added solar noon event Apr 15, 2017
.gitignore
.swiftlint.yml
Daylight.podspec Adding podspec and license. updating readme Apr 20, 2017
LICENSE
Package.swift First commit. Julian date conversion Mar 25, 2017
README.md Adding podspec and license. updating readme Apr 20, 2017

README.md

daylight

A swift package that provides NOAA astrological algorithms for sunrise and sunset times

A port of the go library astrotime

You can either use the interface with a Day struct containing the calendar date of interest, or use the interface of a Date object.

Note that using the Date object's interface will use the calendar date at the timezone of the Location.

The SolarEvent enum is used to specify the event of interest.

Example

let julyFirst = Day(year: 2015, month: 7, day: 1)
let newyork = Location(tz: TimeZone(identifier: "America/New_York")!,
                       coords: Coords(latitude: 40.642, longitude: -74.017))
let sunrise = julyFirst.timeOf(.sunrise, at: newyork)

//Format it to display in location's timezone
let dateFormatter = DateFormatter()
dateFormatter.timeZone = newyork.tz
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .long
print("Sunrise: \(dateFormatter.string(from: sunrise))")

Interface

public enum SolarEvent {
    case sunrise
    case noon
    case sunset
    case civilDawn
    case civilDusk
    case nauticalDawn
    case nauticalDusk
    case astronomicalDawn
    case astronomicalDusk
}

public struct Location {
    public let tz: TimeZone
    public let coords: CLLocationCoordinate2D
}

public struct Day {
    public let year: Int, month: Int, day: Int
    public func timeOf(_ solarEvent: SolarEvent, at location: Location) -> Date
}

public extension Date {
    public func timeOf(_ solarEvent: SolarEvent, at location: Location) -> Date
    public func timeOfNext(_ solarEvent: SolarEvent, at location: Location) -> Date
}

Running tests

In addition to with XCode, you can run the test suite via the command-line with the following command:

swift test