freakent / node-red-contrib-sunevents

A node for node-red that generates events based on the position of the Sun at the appropriate time of day.
Apache License 2.0
15 stars 13 forks source link

fix (and test) for case where events for today are not in suncalc's getTimes(today) #19

Closed b3nj1 closed 3 years ago

b3nj1 commented 3 years ago

Hi,

Due to timezones and whatnot, suncalc.getTimes(today,...) will return events that happened yesterday and/or will happen tomorrow. I ran across this when my "nadir" events were never triggered after US/California in November.

This PR has:

  1. fixes for the tests so that they use the test date as the reference for moment.calendar() calls so "Today" works.
  2. refactors lib/sunevents to a) split out getTimes() for easier (for me), b) handle the case where events need to be pulled from "tomorrow"
  3. adds a test to test the case above which passes now with point 2

Thanks for your consideration,

freakent commented 3 years ago

For v3 I have changed substantially the way this node works with suncalc. I thought about you update for some time but decided the only way to make this really robust was to run suncalc twice and ensure we have at least 24 hours of events. Thanks for your suggestions. Happy to accept any more ideas for v3!