Git Product home page Git Product logo

Comments (5)

Thornye avatar Thornye commented on September 17, 2024 1

@tomaszstos It's correct, times given in UTC as indicated by +00:00

from suntime.

dschwen avatar dschwen commented on September 17, 2024

This is true even for north america (US Mountain time).

from suntime.

dschwen avatar dschwen commented on September 17, 2024

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.

Jahor avatar Jahor commented on September 17, 2024

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.

yasirroni avatar yasirroni commented on September 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.