mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.1k stars 417 forks source link

Problem with sunset calculation: I don't get the right time #22

Closed MBenoli closed 10 years ago

MBenoli commented 10 years ago

Hello!

First of all, thank you for this great library!

Unfortunately, I have a problem when calculating sunset hours.

Here is an example to illustrate my problem: If I go on: http://www.suncalc.net The sunset hour for today in Brussels is 21h37. When I use the JavaScript Library Downloaded on GitHub, I obtain 21h40. Why this difference between the two results?

Thank you!

Michael.

mourner commented 10 years ago

Can you provide specific latitude, longitude, date and expected result?

MBenoli commented 10 years ago

Sure!

I use: lat=50.85, long=4.35, date=23/05/2014, expected result 21h37 for sunset.

Thanks!

mourner commented 10 years ago

The following code

console.log(SunCalc.getTimes(new Date('2014-05-23'), 50.85, 4.35).sunset);

returns Fri May 23 2014 22:36:58 GMT+0300 (EEST), which is 21h37 in your timezone. So I can't reproduce your issue.

MBenoli commented 10 years ago

Thank you for your answer!

I've just found the problem. It has nothing to do with the SunCalc algorithm. Sorry for the inconvenience.

mourner commented 10 years ago

Thanks! What was the problem?

MBenoli commented 10 years ago

I've just started using Titanium to build mobile applications. The problem is linked to the Date object. When I try the code with Firebug it works perfectly, but when I run it with Titanium it doesn't work. The date object doesn't return a valid date. I just figured out how to fix it but I still wonder why there is such a problem. I have my ideas but still... If I may benefit from this message to ask you another question. I would like to ask you if it is possible to use SunCalc to get the hour for a specific day of the year knowing the elevation angle? For example: At which hour the sun will have an elevation angle of -8.5 degrees in Belgium on the 24/05/2014. Result expected is 22h44. I just ask in the case you may be able to give me a quick answer otherwise I will work on it to figure it out. Thank you very much!

mourner commented 10 years ago

Yeah, check out SunCalc.addTime method in the docs.

MBenoli commented 10 years ago

Thanks! I'll take a look ;)