Comments (3)
I suspect this is the same issue I reported in #12, with a difference that you are on the other side of UTC so the sunrise is the wrong day instead of sunset.
I expanded my workaround, see it this works.
import datetime
from suntime import Sun
import pytz
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
latitude = 56.49771
longitude = 82.0475315
tz = pytz.timezone('Asia/Novosibirsk')
day = datetime.datetime(2021, 4, 24)
print(f'For {latitude}, {longitude}, tz={tz}, day={day}')
print('sunrise:', sunrise(latitude, longitude, day, tz))
print('sunset: ', sunset(latitude, longitude, day, tz))
print()
latitude = 39.8895
longitude = -77.0353
tz = pytz.timezone('US/Eastern')
day = datetime.datetime(2020, 4, 29)
print(f'For {latitude}, {longitude}. tz={tz}, day={day}')
print('sunrise:', sunrise(latitude, longitude, day, tz))
print('sunset: ', sunset(latitude, longitude, day, tz))
Running that I get
For 56.49771, 82.0475315, tz=Asia/Novosibirsk, day=2021-04-24 00:00:00
workaround: subtracted 1 day from sunrise time
sunrise: 2021-04-24 06:04:00+07:00
sunset: 2021-04-24 20:57:00+07:00
For 39.8895, -77.0353. tz=US/Eastern, day=2020-04-29 00:00:00
sunrise: 2020-04-29 06:10:00-04:00
workaround: added 1 day to sunset time
sunset: 2020-04-29 20:01:00-04:00
from suntime.
Thank for reply
I can fix it but I just want to report to module developer for module inside fix
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)
- ValueError on corner case
- 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
- Inconsistent sunrise times between neighbouring zones HOT 5
- 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
- Buglet in example HOT 1
- 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.