sunlitt / sunkit Goto Github PK
View Code? Open in Web Editor NEWSunKit is a Swift library which uses math and trigonometry to compute several information about the Sun.
License: Apache License 2.0
SunKit is a Swift library which uses math and trigonometry to compute several information about the Sun.
License: Apache License 2.0
Based on the issue opened on MoonKit, SunKit need to be updated with the same fix.
For more info -> Sunlitt/MoonKit#1
Hey,
I used SunKit and MoonKit in my upcoming application. I like them and it's great that the classes are still alive and that you keep improving them.
In practical implementation, I've encountered difficulties when working with time zones and would have a tip for an improvement that would greatly simplify their use.
My difficulties:
When I want to use a Sun class for a time zone other than the current time zone, I have to work very carefully with the time zone.
For example: the facility is located in Prague and I need the position of the sun during the day in Cupertino.
This is not a safe and convenient solution.
That's why I propose to initialize the Sun class with the TimeZone class.
The Sun class can then do all the necessary conversions for time zones by itself:
Michal Kus
It would be practical if Sun and Moon had a common ancestor that had properties that both classes have the same (date, altitude, rise, set ....).
Right now I have two almost identical methods, although one would be enough.
Thanks, Michal Kůs
When testing SunKit, the dumpDateInfos
function includes the following:
Civil dusk -> Tuesday, May 2, 2023 at 5:31:09 AM Mountain Daylight Time
Civil Dawn -> Tuesday, May 2, 2023 at 8:21:42 PM Mountain Daylight Time
Nautical Dusk -> Tuesday, May 2, 2023 at 4:56:05 AM Mountain Daylight Time
Nautical Dawn -> Tuesday, May 2, 2023 at 8:56:46 PM Mountain Daylight Time
Astronomical Dusk -> Tuesday, May 2, 2023 at 4:18:26 AM Mountain Daylight Time
Astronomical Dawn -> Tuesday, May 2, 2023 at 9:34:25 PM Mountain Daylight Time
In each case, dawn is shown as being in the evening, while dusk is in the morning.
I thought at first that the dawn times were for tomorrow, i.e. the next time dawn arrived, but they all show the same date. Printing their UTC values shows the same issue, dusk occurs before dawn:
Civil dawn: 2023-05-03 02:21:42 +0000
Civil dusk: 2023-05-02 11:31:09 +0000
Nautical dawn: 2023-05-03 02:56:46 +0000
Nautical dusk: 2023-05-02 10:56:05 +0000
Astronomical dawn: 2023-05-03 03:34:25 +0000
Astronomical dusk: 2023-05-02 10:18:26 +0000
I don’t know if this means dawn and dusk times are reversed or if there’s some other problem.
My Package.resolved
shows that I’m using tag 2.6.3, so I should be up to date.
Hello,
I have downloaded SunKit and installed in via the Swift Package Manager in Xcode.
I want to show in a view (example the ContentView) for example the sunrise time.
Is it possible to provide me the code to do this. As I am relatively new to SwiftUI (You have to start somewhere I guess), I am a little bit lost 'in the moment' :)
Is it possible to help me and show me how I can show these time in a Xcode View?
Your help would be appreciated.
I tested how the package works after plugging in TimeZone. Unfortunately, I found a bug in working with daylight saving time.
Example: sunrise in Los Angeles
March 11: calculates 07:08, (this is an error, should be 06:08)
March 12th is the end of daylight saving time
March 13: calculates 07:06 (this is correct)
This error is not in the MoonKit package.
func testSun() throws {
//https://gml.noaa.gov/grad/solcalc/sunrise.html
//https://www.timeanddate.com/sun/usa/los-angeles?month=3&year=2023
guard let pst = TimeZone(abbreviation: "PST") else {
abort()
}
guard let utc = TimeZone(abbreviation: "UTC") else {
abort()
}
let location: CLLocation = .init(latitude: 34.052235, longitude: -118.243683)
let sun = Sun.init(location: location, timeZone: pst)
sun.setDate(SunKit.createDateCustomTimeZone(day: 11, month: 3, year: 2023, hour: 22, minute: 00, seconds: 00, timeZone: pst))
XCTAssertEqual(sun.sunrise.toString(pst), "03/11, 06:08") //XCTAssertEqual failed: ("03/11, 07:08") is not equal to ("03/11, 06:08")
XCTAssertEqual(sun.sunset.toString(pst), "03/11, 17:58") //XCTAssertEqual failed: ("03/11, 18:58") is not equal to ("03/11, 17:58")
XCTAssertEqual(sun.sunrise.toString(utc), "03/11, 14:08") //XCTAssertEqual failed: ("03/11, 15:08") is not equal to ("03/11, 14:08")
XCTAssertEqual(sun.sunset.toString(utc), "03/12, 01:58") //XCTAssertEqual failed: ("03/12, 02:58") is not equal to ("03/12, 01:58")
sun.setDate(SunKit.createDateCustomTimeZone(day: 13, month: 3, year: 2023, hour: 22, minute: 00, seconds: 00, timeZone: pst))
XCTAssertEqual(sun.sunrise.toString(pst), "03/13, 07:06")
XCTAssertEqual(sun.sunset.toString(pst), "03/13, 18:59")
XCTAssertEqual(sun.sunrise.toString(utc), "03/13, 14:06")
XCTAssertEqual(sun.sunset.toString(utc), "03/14, 01:59")
}
extension Date {
func toString(_ timeZone: TimeZone) -> String {
let df = DateFormatter()
df.timeZone = timeZone
let custom = DateFormatter.dateFormat(fromTemplate: "MMdd HH:mm",
options: 0,
locale: Locale(identifier: "en"))
df.dateFormat = custom
return df.string(from: self)
}
}
extension TimeZone {
func offset(_ date: Date) -> Double {
let res =
Int(self.secondsFromGMT(for: date))
+ Int(self.daylightSavingTimeOffset(for: date))
- Int(Calendar.current.timeZone.secondsFromGMT(for: date))
- Int(Calendar.current.timeZone.daylightSavingTimeOffset(for: date))
print("\(date.toString()) \(Int(self.secondsFromGMT(for: date)/3600)), \(Int(self.daylightSavingTimeOffset(for: date)/3600)), \(Int(Calendar.current.timeZone.secondsFromGMT(for: date)/3600)), \(Int(Calendar.current.timeZone.daylightSavingTimeOffset(for: date)/3600))")
return Double(res)/3600.0
}
}
Hello,
thank you for your awesome work.
As the sun moves from sunrise to sunset in a given location you provide the azimuth of the sun on sunrise and sunset.
I have a question: is it possible to have the data of the current position of the sun. For example if it is 10h30 to see the position of the sun on the map between sunrise and sunset, and if the time evolves you see the sun on a map moving?
is this possible?
Hello I am a little bit confused.
I want to see the sunset time of tomorrow. I am a little bit stuck with the date.
How can I modify tthe code to retrieve the sunset time of tomorrow?
If you delete private in getDateFrom, it will be possible to calculate the time for any elevation, e.g. nautical twilight (-12°).
WIth the introduction of the new way to handle timezones backwards compatibility may be compromised.
Implement a way to guarantee backwards compatibility.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.