@@ -95,14 +95,7 @@ def get_sunrise_sunset_transit(latitude_deg, longitude_deg, when):
95
95
else :
96
96
utc_offset = 0
97
97
#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
106
99
SHA = utc_offset / 3600 * 15.0 - longitude_deg # Solar hour angle
107
100
TT = 2 * math .pi * day / 366
108
101
decl = \
@@ -163,15 +156,10 @@ def get_sunrise_sunset_transit(latitude_deg, longitude_deg, when):
163
156
*
164
157
(12 / math .pi )
165
158
)
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 )
175
163
return sunrise_time , sunset_time , transit_time
176
164
177
165
@check_aware_dt ('when' )
0 commit comments