Git Product home page Git Product logo

suncalc.swift's Introduction

SunCalc.swift

A direct port of suncalc javascript library (commit b08d1f6f8). Which means this port inherits the same accuracy and issues with the original javascript library.

Updated

Now SunCalc can handle polar region's "Mid-night sun". Errors are now embeded in SunCalc class:

SunCalc.SolarEventError.sunNeverRise
SunCalc.SolarEventError.sunNeverSet

SunCalc.LunarEventError.moonNeverRise(Date?) // An optional date for moonset time.
SunCalc.LunarEventError.moonNeverSet(Date?) // An optional date for moonrise time.

Location now become SunCalc.Location.

Examples

// DateFormatter
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .short
formatter.timeZone = .current

// Sunrise and sunset
let sunCalc = SunCalc()
let now = Date()
let location = SunCalc.Location(latitude: 25.0, longitude: 120.0)
if let riseTime = try? sunCalc.time(ofDate: now, forSolarEvent: .sunrise, atLocation: location) {
    let sunrise = formatter.string(from: riseTime)
    print("Sunrise: \(sunrise)")
}
if let setTime = try? sunCalc.time(ofDate: now, forSolarEvent: .sunset, atLocation: location) {
    let sunset = formatter.string(from: setTime)
    print("Sunset: \(sunset)")
}

// Moon rise and moon set
let moonTimes = try? sunCalc.moonTimes(date: now, location: location)
if let moonTimes = moonTimes {
    print("Moonrise: \(formatter.string(from: moonTimes.moonRiseTime))")
    print("Moonset: \(formatter.string(from: moonTimes.moonSetTime))")
}

Known Issue

Moon rise and set time sometimes not correct. See Issue #1

LICENSE

BSD License

Copyright (c) 2018, Venj Chu

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

suncalc.swift's People

Contributors

venj avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

suncalc.swift's Issues

nadir is not calculated (always throws)

try? suncalc.time(ofDate: date, forSolarEvent: .nadir, atLocation: location) always seems to throw

I think this is because it calculates jset for .nadir (and fails) even though jset is meaningless in this context

Moon rise and moon set time in polar area is not correct.

Moon rise and set time in polar area that has "mid-night sun" is not correct.

Current SunCalc.LunarEventError.moonNeverRise and SunCalc.LunarEventError.moonNeverSet do not have any relationship with "mid-night sun" in polar area.

I will look into this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.