Skip to content

Instantly share code, notes, and snippets.

@craigcalef
Created April 18, 2019 23:06
Show Gist options
  • Save craigcalef/924cdd28475bc21e3f9319caf3b4b311 to your computer and use it in GitHub Desktop.
Save craigcalef/924cdd28475bc21e3f9319caf3b4b311 to your computer and use it in GitHub Desktop.
Calculate length of day change over the year
import ephem
import datetime
# ephem.localtime(ephem.next_summer_solstice('2019-1-1'))
s = ephem.Sun()
o = ephem.city('Boston')
yesterday_len = 0
for i in range(0, 365):
d = datetime.datetime(2019,1,1,16,0) + datetime.timedelta(i)
o.date = d
daylen = o.next_setting(s) - o.previous_rising(s)
#print("{},{},{}".format(d, o.previous_rising(s), o.next_setting(s), (daylen-yesterday_len)))
print("{},{}".format(d, (daylen-yesterday_len)))
yesterday_len = daylen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment