-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dates with times before a certain time return times for previous day #11
Comments
I have a similar issue, this date... Wed Feb 12 2014 00:47:44 GMT+0100 ...which is a console.log on a valid js Date object, gives me back the SunCalc times for the day before. This bug destroys the accuracy and credibility of what I'm trying to build. Did you ever get a fix for your issue? |
As far as I know, the issue is not fixed yet. However, a simple workaround is just to set the hours to the mid of the day, you'll get the correct times that way. |
Thanks, that's going to be some serious refactoring for me as in the real-time system I'm building the date is also a display date. Still hoping for a real fix, but I see little activity here. |
replace your gettimes calls with a |
Thanks, that is helpful. It still means I need to split the display time from the internal time, but that looks like the only way forward, and doable. |
@fchristant while I'm going to fix the problem, please don't complain — this is open source, if something's not working for you, I'm happily accepting pull requests. There's little activity on this repo because it's pretty much feature complete, this is a low priority bug because there's an easy workaround, and I'm focused on more important things like https://github.com/Leaflet/Leaflet. |
I'm not complaining, I'm reporting an issue. With "little activity" I mean activity on the issues, as in communication. I'm in favor of at least a basic acknowledgement, even a message saying "sorry, I won't fix this" is better than nothing. Anyway, thanks for clarifying. |
OK, now I see what's going on here — SunCalc calculates all the times after it gets the time of the nearest solar transit. But solar transit isn't strictly 12am — e.g. if it's 12:44am, then 0:43am as input will result in dates of the previous day since its transit is closer. |
Thanks for the explanation. I did manage to work around the issue using the trick above, so no issues. I actually just launched a first version of a visualization that combines most info that your lib returns (except for azimuth): http://www.jungledragon.com/daylight This one is optimized for (wildlife) photographers. It has stateful URLs and one can even add a "light period" appointment to one's calendar. I'm sharing this just to let you know how valuable you library is. So thank you very much, and I hope you'll see better days in your country soon. |
Not sure if the issue I'm having is related but my dates all seem wrong. In the console this is what I see... first is valid js date followed by dump of my t var. It's showing dawn time as evening of day before and dusk as morning of current day... Wed Apr 23 2014 15:46:54 GMT-0400 (Eastern Daylight Time) Object {solarNoon: Wed Apr 23 2014 02:23:06 GMT-0400 (Eastern Daylight Time), nadir: Tue Apr 22 2014 14:23:06 GMT-0400 (Eastern Daylight Time), sunrise: Tue Apr 22 2014 19:44:26 GMT-0400 (Eastern Daylight Time), sunset: Wed Apr 23 2014 09:01:45 GMT-0400 (Eastern Daylight Time), sunriseEnd: Tue Apr 22 2014 19:47:06 GMT-0400 (Eastern Daylight Time)…} dawn: Tue Apr 22 2014 19:18:13 GMT-0400 (Eastern Daylight Time) |
@emcjh it shows you times in your local time zone, you need to convert them according to the time zone of the location if you want precise local times and dates. |
Not sure I understand your comment. My local time zone and the time zone of the location I want to get dawn/dusk times are the same. If I submit a date of Apr 23, 2014 shouldn't I get the dawn time for Apr 23 and dusk time for April 23? Why does dawn show evening of Apr 22 and dusk as morning of Apr 23? Or am I just really missing something. |
If your timezones are good, why is sunrise happening at 7:44pm? |
That's exactly what I'm trying to figure out. I called getTimes() with a date of Apr 23 so why is sunrise returned as 7:44pm of Apr 22? Pretty sure I'm using the latest version of suncalc.js as I just downloaded it from here yesterday. Thanks for your assistance with this. |
@emcjh What happens if you do this: var today = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 12, 0, 0, 0, 0); |
@fchristant Dates and times still appear incorrect. I assumed d in your example is a js date object. My code: Results in console: Thu Apr 24 2014 12:00:00 GMT-0400 (Eastern Daylight Time) (index):1844 |
hmmm, well at least this means your issue is not related to the issue described at the beginning of the thread, we just excluded that. |
No issue for me. It just required converting the result times to local timezone. Thanks! |
I still experience this issue. Here an example:
This returns: If you calculate the local time for Sydney this will be: This means that for the date and time of 15th of March 23:59 it returns the sunrise and sunset for the following day. I have tested this with the latest version of the library. It seems to me that the conversion into and from julian could be the reason. But I am not an expert and don't understand the calculations there, so it could be something else as well. |
+1 on this issue, currently hacking around it w/ the midday line but would love a fix! |
+1 I have the same problem in Gladys ( It's a home assistant project => https://github.com/GladysProject/Gladys ). I calculate the sunrise at midnight, and it calculates for the day before Thx a lot for this awesome library ! |
see title, when inputting a date that has a time before 00:40:54, the times are for the previous day.
suncalc.getTimes(new Date(2013, 10, 20, 0, 40, 53), 52.2, 5.1)
returns times for november 19th, but a second later returns times for november 20th as expected.
The text was updated successfully, but these errors were encountered: