Latest 1.1.1
License MIT
Platforms ios 8.0, requires ARC

A Swift 3 project for calculating sunrise and sunset times.

Integration using CocoaPods

To use CocoaPods to install SwiftySunrise, add it to your Podfile:

target 'YourApp' do
    pod 'SwiftySunrise'


SwiftySunrise returns a Date struct, for example:

let today = Date()
let sunriseInLondon = SwiftySunrise.sunPhaseTime(forPhase: .sunrise, withTwilightType: .official, onDay: today, atLatitude: 51.527383, andLongitude: -0.0881353)

For convenience, the Date extension can be used:

let today = Date()
let sunriseInLondon = today.toSunPhase(forPhase: .sunrise, withTwilightType: .official, atLatitude: 51.527383, andLongitude: -0.0881353)

or for today, the failable initializer is another option:

let sunriseInLondon = Date(sunPhaseToday: .sunrise, latitude: 51.527383, longitude: -0.0881353)

SwiftySunrise only uses the Foundation framework, making it cross platform compatible.

Time zones

SwiftySunrise returns times in UTC. For display, times can be converted like in the following example:

guard let sunriseInSanFrancisco = Date().toSunPhase(forPhase: .sunrise, withTwilightType: .official, atLatitude: 37.7576171, andLongitude: -122.5776844) else { return }

guard let pacificTimeZone = TimeZone(identifier: "US/Pacific") else { return }
let dateFormatter = DateFormatter()
dateFormatter.timeZone = pacificTimeZone
dateFormatter.dateFormat = "HH:mm"

let timeInSanFrancisco = dateFormatter.string(from: sunriseInSanFrancisco) // "07:43"

Twilight Types

For each phase (sunrise or sunset), times can be requested for the following twilight types:

  • Official
  • Civil
  • Nautical
  • Astronomical


The MIT License (MIT)

Latest podspec

    "name": "SwiftySunrise",
    "version": "1.1.1",
    "summary": "Sunrise and sunset times in Swift.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Tom Weightman": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.1.1"
    "requires_arc": true,
    "platforms": {
        "ios": "8.0"
    "source_files": "SwiftySunrise/*.swift",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This