Latest 0.1.0
Homepage https://github.com/martinc/daylight
License MIT
Platforms ios 8.0
Authors

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

Latest podspec

{
    "name": "Daylight",
    "version": "0.1.0",
    "summary": "A swift package that provides NOAA astronomical algorithms for times for sunrise, sunset, dawn, dusk, and noon",
    "description": "Daylight is a swift package that provides methods to generate the times of solar events in a given location on a given calendar date.nThese solar events include sunrise, sunset, noon, civil dawn and dusk, nautical dawn and dusk, and astronomical dawn and dusk.nIt provides algorithms used by NOAA.",
    "homepage": "https://github.com/martinc/daylight",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Martin Ceperley": "[email protected]"
    },
    "source": {
        "git": "https://github.com/martinc/daylight.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Sources/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This