Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kstopa committed Mar 10, 2024
2 parents 5f80545 + 705ec59 commit 1b9c9d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from setuptools import setup

from suntime import __version__, __author__, __license__

# read the contents of your README file
from os import path
Expand All @@ -10,13 +10,13 @@
long_description = f.read()

setup(name='suntime',
version='1.3.1',
version=__version__,
description='Simple sunset and sunrise time calculation python library',
long_description=long_description,
long_description_content_type='text/markdown',
author='Krzysztof Stopa',
author=__author__,
url='https://github.com/SatAgro/suntime',
copyright='Copyright 2024 SatAgro',
license='LGPLv3',
license=__license__,
packages=['suntime'],
install_requires=['python-dateutil'])
4 changes: 4 additions & 0 deletions suntime/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .suntime import Sun, SunTimeException

__version__ = '1.3.2'
__author__ = 'Krzysztof Stopa'
__license__ = 'LGPLv3'
15 changes: 10 additions & 5 deletions suntime/suntime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
import warnings
from datetime import date, datetime, timedelta, time, timezone
from datetime import datetime, timedelta, time, timezone


# CONSTANT
Expand All @@ -24,7 +24,7 @@ def __init__(self, lat, lon):

self.lngHour = self._lon / 15

def get_sunrise_time(self, at_date=date.today(), time_zone=timezone.utc):
def get_sunrise_time(self, at_date=datetime.now(), time_zone=timezone.utc):
"""
:param at_date: Reference date. datetime.now() if not provided.
:param time_zone: pytz object with .tzinfo() or None
Expand All @@ -37,7 +37,7 @@ def get_sunrise_time(self, at_date=date.today(), time_zone=timezone.utc):
else:
return datetime.combine(at_date, time(tzinfo=time_zone)) + time_delta

def get_sunset_time(self, at_date=date.today(), time_zone=timezone.utc):
def get_sunset_time(self, at_date=datetime.now(), time_zone=timezone.utc):
"""
Calculate the sunset time for given date.
:param at_date: Reference date. datetime.now() if not provided.
Expand All @@ -51,13 +51,14 @@ def get_sunset_time(self, at_date=date.today(), time_zone=timezone.utc):
else:
return datetime.combine(at_date, time(tzinfo=time_zone)) + time_delta

def get_local_sunrise_time(self, at_date, time_zone):
def get_local_sunrise_time(self, at_date=datetime.now(), time_zone=None):
""" DEPRECATED: Use get_sunrise_time() instead. """
warnings.warn("get_local_sunrise_time is deprecated and will be removed in future versions."
"Use get_sunrise_time with proper time zone", DeprecationWarning)

return self.get_sunrise_time(at_date, time_zone)

def get_local_sunset_time(self, at_date, time_zone):
def get_local_sunset_time(self, at_date=datetime.now(), time_zone=None):
""" DEPRECATED: Use get_sunset_time() instead. """
warnings.warn("get_local_sunset_time is deprecated and will be removed in future versions."
"Use get_sunset_time with proper time zone.", DeprecationWarning)
Expand All @@ -73,6 +74,10 @@ def get_sun_timedelta(self, at_date, time_zone, is_rise_time=True, zenith=90.8):
:return: timedelta showing hour, minute, and second of sunrise or sunset
"""

# If not set get local timezone from datetime
if time_zone is None:
time_zone = datetime.now().tzinfo

# 1. first get the day of the year
N = at_date.timetuple().tm_yday

Expand Down
7 changes: 6 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from datetime import datetime
from datetime import datetime, date
from dateutil import tz

from suntime import Sun, SunTimeException
Expand Down Expand Up @@ -46,6 +46,11 @@ def test_get_sunset_time(self):
local_sunset = self.sun.get_local_sunset_time(datetime(2024, 3, 11), tz.gettz('America/Los_Angeles'))
self.assertEqual(utc_sunset, expected_sunset)
self.assertEqual(local_sunset, expected_sunset)
# Check with no params
utc_default_sunrise = self.sun.get_sunrise_time()
local_default_sunrise = self.sun.get_local_sunrise_time()
self.assertEqual(utc_default_sunrise.date(), datetime.now().date())
self.assertEqual(local_default_sunrise.date(), datetime.now().date())


class TestEastSun(unittest.TestCase):
Expand Down

0 comments on commit 1b9c9d3

Please sign in to comment.