The next_setting()
and previous_setting()
functions do not consult the current value of ephem.now()
. Instead, they look for dates previous to or subsequent to the .date
of the Observer
object — so the results you are getting only happen in my own experiments here on my laptop if the observer .date
somehow gets set to a day in the future. Here are the setting times that I get if I use exactly the date and time you supplied:
import ephem
m = ephem.Observer()
m.long = '7:42:00'
m.lat = '45:04:00'
m.date = '2012/10/16 16:02:00'
print m.next_setting(ephem.Sun(), use_center=True)
# --> 2012/10/16 16:40:27
print m.previous_setting(ephem.Sun())
# --> 2012/10/15 16:44:05
Could you try running this script and see what you get as a result? The ephem.__version__
that currently displays on my laptop is 3.7.5.1, just in case that is a difference between us.
So: if you see odd results like this, then instead of printing and comparing the value of ephem.now()
with the sunset times, you need to investigate the relationship between the observer's .date
attribute and the sunset times you get out. If you can produce a little sample script like the one I show above, that sets its own times, instead of relying on now()
to show a mistake that PyEphem is making (since by the time I see your question, my now()
is obviously a bit different from your original "now"!), then I'll do my best to track down the problem.