Added solar time.#156
Conversation
| ### Solar time | ||
|
|
||
| ```js | ||
| SunCalc.getSolarTime(/*Date*/ date, /*Number*/ latitude, /*Number*/ utcOffset) |
There was a problem hiding this comment.
Based on the original source code, it appears this should use longitude.
Second parameter should be utcOffset and third parameter should be Longitude.
There was a problem hiding this comment.
Fixed. I've been trying different ways to achieve the same. Missed the readme. Thanks.
| var localSolarTime = date.getHours() + timeCorrection / 60 + date.getMinutes() / 60; | ||
|
|
||
| var solarDate = new Date(0, 0); | ||
| solarDate.setMinutes(+localSolarTime * 60); |
There was a problem hiding this comment.
Is there a better way to handle the date object when it crosses between days? Using 23:58 as a starting time would be a good test.
There was a problem hiding this comment.
I would recommend switching to a date object as the return.
return new Date(date.getTime() + timeCorrection * 60 * 1000);That will handle the above issue and allow the user to format the date however they want.
There was a problem hiding this comment.
Works with any date and time, including seconds and milliseconds.
|
Thanks for the PR! Is there a reason to separately introduce this method if you can already get |
|
Hi @mourner, thank you for your time. The main reason behind the PR is that solarNoon is always the same for a given latitude and longitude (as stated, the sun's highest position). The solar time is a calculation of the passage of time based on the position of the Sun in the sky, which varies with the given date. If there's already a way to achieve this with the library, please let me know. I struggle a bit with the terms :) |
What does this PR do?
Adds the solar time function to the library.
What issues does it solve?
#136