Comments (5)
@tomaszstos It's correct, times given in UTC as indicated by +00:00
from suntime.
This is true even for north america (US Mountain time).
from suntime.
Ended up using pyephem instead:
#!/usr/bin/env python3
import ephem
from datetime import datetime, timedelta
# current time in UTC
now = datetime.utcnow()
#Make an observer
coop = ephem.Observer()
#PyEphem takes and returns only UTC times
coop.date = now.strftime("%Y-%m-%d %H:%M")
#Location
coop.lon = str(-112)
coop.lat = str(44)
coop.elev = 1450
#To get U.S. Naval Astronomical Almanac values, use these settings
coop.pressure= 0
coop.horizon = '-0:34'
times = [
coop.previous_rising(ephem.Sun()),
coop.next_rising(ephem.Sun()),
coop.previous_setting(ephem.Sun()),
coop.next_setting(ephem.Sun())
]
minute = timedelta(minutes=1)
prev_sunrise, next_sunrise, prev_sunset, next_sunset = [(ephem.localtime(time) - now) / minute for time in times]
print("previous sunrise (minutes): ", prev_sunrise)
print("next sunrise (minutes): ", next_sunrise)
print("previous sunset (minutes): ", prev_sunset)
print("next sunset (minutes): ", next_sunset)
from suntime.
It's incorrect, as when translated to local timezone it causes sunrise to be next day:
Sunrise
sun.get_sunrise_time() = 2021-05-16 19:12:00+00:00
sun.get_local_sunrise_time() = 2021-05-17 07:12:00+12:00
Sunset
sun.get_sunset_time() = 2021-05-16 05:22:00+00:00
sun.get_local_sunset_time() = 2021-05-16 17:22:00+12:00
from suntime.
In UTC, this is the expected behavior I think. But, in local, it should not be like that.
My solution 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 (16)
- ValueError on corner case
- Local Sunset time wrong when UTC sunset is in following day HOT 8
- Did suntime change? HOT 2
- North and south latitude problems HOT 4
- Big issue of suntime HOT 3
- 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
- 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.