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

Times seem off? #51

Closed Broham closed 9 years ago

Broham commented 9 years ago

I'm making a call to getTimes like below:

getTimes(new Date("5/13/15 23:53"), Number("-122.4258917"), Number("37.7745986"));

Which returns:

{  
   "solarNoon":"2015-05-14T09:26:36.756Z",
   "nadir":"2015-05-13T21:26:36.756Z",
   "sunrise":"2015-05-14T01:26:51.946Z",
   "sunset":"2015-05-14T17:26:21.566Z",
   "sunriseEnd":"2015-05-14T01:21:59.805Z",
   "sunsetStart":"2015-05-14T17:31:13.707Z",
   "dawn":"2015-05-14T02:11:28.048Z",
   "dusk":"2015-05-14T16:41:45.464Z",
   "nauticalDawn":"2015-05-14T02:59:20.761Z",
   "nauticalDusk":"2015-05-14T15:53:52.751Z",
   "nightEnd":"2015-05-14T03:45:00.407Z",
   "night":"2015-05-14T15:08:13.104Z",
   "goldenHourEnd":"2015-05-14T00:17:58.717Z",
   "goldenHour":"2015-05-14T18:35:14.795Z"
}

These times seem off - for example it has sunrise at 2015-05-14T01:26:51.946Z which I'm reading as 1:26 am (correct?). Similarly night is 2015-05-14T15:08:13.104Z aka 3pm?

Are the times returned for a specific time zone?

mourner commented 9 years ago

It returns times for the user's timezone.

Broham commented 9 years ago

Oh interesting, thanks for the info. So I created a Node.js api using this library and it is hosted on a heroku server (somewhere). Does this mean that where ever the server is hosted that the sun rose at 1:26 am and set at 3pm on May 14th, 2015? Why am I passing in a lat/long if it just uses the users timezone?

mourner commented 9 years ago

No, it means that if server sunrise is at 7:26am and it shows 1:26am to you, you have a 6 hour timezone difference between you and the server.

mourner commented 9 years ago

BTW there's already a Heroku SunCalc server here https://github.com/RandomEtc/suncalc-api

Broham commented 9 years ago

beautiful - thanks