Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rlxone/solarnoaa
🌞 Calculation of local times of sunrise, solar noon, sunset, azimuth, elevation based on the calculation procedure by NOAA
https://github.com/rlxone/solarnoaa
azimuth elevation solar sunrise sunset swift
Last synced: 3 days ago
JSON representation
🌞 Calculation of local times of sunrise, solar noon, sunset, azimuth, elevation based on the calculation procedure by NOAA
- Host: GitHub
- URL: https://github.com/rlxone/solarnoaa
- Owner: rlxone
- License: mit
- Created: 2018-08-21T12:53:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T18:30:43.000Z (over 3 years ago)
- Last Synced: 2024-10-31T16:33:14.001Z (13 days ago)
- Topics: azimuth, elevation, solar, sunrise, sunset, swift
- Language: Swift
- Homepage:
- Size: 113 KB
- Stars: 30
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SolarNOAA
Calculation of local times of `sunrise`, `solar noon`, `sunset`, `azimuth`, `elevation` based on the calculation procedure by [NOAA](http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html)## Installation
### CocoaPods
[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate **SolarNOAA** into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'SolarNOAA', '~> 1.0.0'
```### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate **SolarNOAA** into your Xcode project using Carthage, specify it in your `Cartfile`:
```ruby
github "rlxone/SolarNOAA" ~> 1.0.0
```### Swift Package Manager
[Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the swift compiler.Once you have your Swift package set up, adding **SolarNOAA** as a dependency is as easy as adding it to the dependencies value of your `Package.swift`.
```swift
dependencies: [
.package(url: "https://github.com/rlxone/SolarNOAA.git", .upToNextMajor(from: "1.0.0"))
]
```## Requirements
- **iOS** 9.0 / **macOS** 10.9 / **tvOS** 9.0 / **watchOS** 2.0
- Swift 5## Usage
```swift
// Chicago coordinates
let latitude = 41.881832
let longitude = -87.623177
// Timezone for UTC-5
let timezone = -5
// Get current date
let date = Date()
var calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "UTC")!
let year = calendar.component(.year, from: date)
let month = calendar.component(.month, from: date)
let day = calendar.component(.day, from: date)
// Get sunrise and sunset in days
let sunriseDaysTime = Solar.sunrise(lat: latitude, lon: longitude, year: year, month: month, day: day, timezone: timezone, dlstime: 0)
let sunsetDaysTime = Solar.sunset(lat: latitude, lon: longitude, year: year, month: month, day: day, timezone: timezone, dlstime: 0)
// Get date from sunrise and sunset days value
let sunriseDate = Date(timeIntervalSince1970: sunriseDaysTime * 24 * 60 * 60)
let sunsetDate = Date(timeIntervalSince1970: sunsetDaysTime * 24 * 60 * 60)
let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "HH:mm:ss"
timeFormatter.timeZone = TimeZone(identifier: "UTC")
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE, MMM d, yyyy"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
print("Chicago sunrise for \(dateFormatter.string(from: date)): \(timeFormatter.string(from: sunriseDate))")
print("Chicago sunset for \(dateFormatter.string(from: date)): \(timeFormatter.string(from: sunsetDate))")
```