Comments (5)
Try the workaround I posted in issue #16
from suntime.
Thanks for the fast answer,
Indeed
import arrow
import datetime
from suntime import Sun
import pytz
time = arrow.get("2020-04-30 01:00:00+05:30")
tz = pytz.timezone("Asia/Kolkata")
# Lucknow
lat_lucknow = 26.848623
long_lucknow = 80.8024271
sun_luckdown = Sun(lat_lucknow, long_lucknow)
# Agra
lat_agra = 27.1761571
long_agra = 77.9099726
sun_agra = Sun(lat_agra, long_agra)
print("Lucknow", sun_luckdown.get_sunrise_time(time).astimezone(tz)) # ==> Lucknow 2020-05-01 05:29:00+05:30
print("Agra", sun_agra.get_sunrise_time(time).astimezone(tz)) # ==> Agra 2020-04-30 05:40:00+05:30
def sunset(lat, lon, dt=None, tz=None):
if dt is None:
dt = datetime.datetime.now()
sun = Sun(lat, lon)
ss = sun.get_local_sunset_time(dt, local_time_zone=tz)
sr = sun.get_local_sunrise_time(dt, local_time_zone=tz)
if ss.utcoffset() < datetime.timedelta(0):
if ss < sr:
ss = ss + datetime.timedelta(1)
print('workaround: added 1 day to sunset time')
return ss
def sunrise(lat, lon, dt=None, tz=None):
if dt is None:
dt = datetime.datetime.now()
sun = Sun(lat, lon)
ss = sun.get_local_sunset_time(dt, local_time_zone=tz)
sr = sun.get_local_sunrise_time(dt, local_time_zone=tz)
if sr.utcoffset() > datetime.timedelta(0):
if ss < sr:
sr = sr - datetime.timedelta(1)
print('workaround: subtracted 1 day from sunrise time')
return sr
print("Lucknow", sunrise(lat_lucknow, long_lucknow, time, tz)) # ==> workaround: subtracted 1 day from sunrise time Lucknow 2020-04-30 05:29:00+05:30
print("Agra", sunrise(lat_agra, long_agra, time, tz)) # ==> Agra 2020-04-30 05:40:00+05:30
returns matching sunrise times, but this issue questions the consistance of the get_sunrise_time
function from the package. If your workaround works well across the line, shouldn't we add it to the implementation ? I can help with writing the PR :)
from suntime.
Yes, it would be nice if some sort of fix would be incorporated into get_sunrise_time and get_sunset_time. My workaround, would probably need some tweaks to handle some edge cases like locations above the arctic circle. I am also not convinced it might be off a minute or so as well.
from suntime.
I also got this problem, but the workaround make us compute both sr
and ss
. The problem only occur on .astimezone(tz)
though. I think get_local_sunrise_time
should not only use .astimezone(tz)
but different _calc_sun_time
.
from suntime.
Solved in #19, just add tz
as input and done.
Usage:
import datetime
import pytz
from suntime import Sun, SunTimeException
latitude = 7.7956
longitude = 110.3695
tz = pytz.timezone("Asia/Jakarta")
day = datetime.datetime(2022, 4, 24)
print(tz.utcoffset(day))
sun = Sun(latitude, longitude)
try:
print("")
print(datetime.datetime.now())
print()
print(sun.get_sunrise_time())
print(sun.get_sunset_time())
print("")
print(sun.get_sunrise_time(tz=tz))
print(sun.get_sunset_time(tz=tz))
from suntime.
Related Issues (20)
- Local Sunset time wrong when UTC sunset is in following day HOT 8
- Sunrise after sunset for NZ coordinates HOT 5
- Did suntime change? HOT 2
- North and south latitude problems HOT 4
- Big issue of suntime HOT 3
- cannot import name 'Sun' from partially initialized module 'suntime' (most likely due to a circular import) HOT 6
- Sunrise local time is out by 1 hour a day before daylight savings starts. Sunset is correct.
- Bug in day wrap for sunset times HOT 2
- No seconds calculations? HOT 1
- get_local_sunrise_time() returns UTC sunrise time. HOT 3
- suppress print() HOT 1
- get_local_sunrise_time changed incompatibly HOT 1
- Commit e9b1fa4 has breaking change HOT 1
- default argument values are cached
- Sunset returned as yesterday HOT 9
- Update datetime with current date HOT 1
- Publish on PiPy HOT 1
- Another ValueError on corner case HOT 1
- Tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from suntime.