Swiftpack.co - THeK3nger/suncalc-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by THeK3nger.
THeK3nger/suncalc-swift 0.2.0
Swift 5 package porting of the original JS https://github.com/mourner/suncalc
⭐️ 4
🕓 3 years ago
.package(url: "https://github.com/THeK3nger/suncalc-swift.git", from: "0.2.0")

suncalc-swift

Swift CI

This is a port for Swift of https://github.com/mourner/suncalc

This code is based on the original Javascript suncalc by Vladimir Agafonkin ("mourner").

This package is based on the initial porting by Shaun Meredith.

// Check Solar Times in Rome on 2020/04/29
// We use SunCalc original implementation for reference values.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd"
formatter.timeZone = TimeZone(abbreviation: "CET")
let someDateTime = formatter.date(from: "2020/04/29")

let romeLat = 41.89193
let romeLon = 12.51133

let sunTimes = SunCalc.getTimes(date: someDateTime!, latitude: romeLat, longitude: romeLon)

let outFormatter = DateFormatter()
outFormatter.dateFormat = "HH:mm"
outFormatter.timeZone = TimeZone(abbreviation: "CET")
let sunriseString = outFormatter.string(from: sunTimes[.sunrise]!)

XCTAssertEqual(sunriseString, "06:11", "Incorrect Sunrise Time")

Project Philosophy

This project starts as a 1:1 port of the JavaScript's suncalcb but it will not stay like that. While I'll try to maintain as much as external API compatibility, I prefer to adopt a more Swifty approach, especially for the internal functions.

GitHub

link
Stars: 4
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics