Skip to content

Commit eabf856

Browse files
authored
Merge pull request #162 from Kuenlun/master
Solves #144 by going back to previous implementation of get_sunrise_sunset_transit function.
2 parents 28c77b0 + a5c4a9f commit eabf856

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

pysolar/util.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,7 @@ def get_sunrise_sunset_transit(latitude_deg, longitude_deg, when):
9595
else :
9696
utc_offset = 0
9797
#end if
98-
99-
# hours (ignore DST) time diff between UTC and the standard meridian for the input longitude
100-
time_diff = int(round(longitude_deg / 15., 0) - utc_offset / 3600)
101-
# the day, and therefore sunrise and sunset, may be different at the input longitude than at the input "when"
102-
local_time = when - timedelta(seconds = utc_offset) + timedelta(hours = time_diff)
103-
104-
day = local_time.timetuple().tm_yday # Day of the year
105-
98+
day = when.timetuple().tm_yday # Day of the year
10699
SHA = utc_offset / 3600 * 15.0 - longitude_deg # Solar hour angle
107100
TT = 2 * math.pi * day / 366
108101
decl = \
@@ -163,15 +156,10 @@ def get_sunrise_sunset_transit(latitude_deg, longitude_deg, when):
163156
*
164157
(12 / math.pi)
165158
)
166-
167-
# tzinfo doesn't matter
168-
local_day = datetime(year = local_time.year, month = local_time.month, day = local_time.day, tzinfo = local_time.tzinfo)
169-
170-
transit_time = local_day + timedelta(hours = time_diff + TON)
171-
transit_time = (transit_time + timedelta(seconds = utc_offset) - timedelta(hours = time_diff)).replace(tzinfo=when.tzinfo)
172-
sunrise_time = transit_time - timedelta(hours = ha)
173-
sunset_time = transit_time + timedelta(hours = ha)
174-
159+
same_day = datetime(year = when.year, month = when.month, day = when.day, tzinfo = when.tzinfo)
160+
sunrise_time = same_day + timedelta(hours = TON - ha)
161+
sunset_time = same_day + timedelta(hours = TON + ha)
162+
transit_time = same_day + timedelta(hours = TON)
175163
return sunrise_time, sunset_time, transit_time
176164

177165
@check_aware_dt('when')

0 commit comments

Comments
 (0)