
    Qf;                     ~	   d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
mZ d dlmZmZmZmZ 	 d dlZn# e$ r	 d dlmZ Y nw xY wd dlmZmZmZmZmZmZmZmZ d dlmZmZ g dZ dZ!d	e"d
e j#        fdZ$de"d
e"fdZ%de"d
e"fdZ&de"d
e"fdZ'de"d
e"fdZ(de"d
e"fdZ)de"d
e"fdZ*de"d
e"fdZ+de"d
e"fdZ,de"d
e"fdZ-de"d
e"fdZ.de"d
e"fdZ/de"d
e"fdZ0de"d
e"fdZ1de"d
efdZ2de"de"de"ded
e"f
dZ3d e"d
e"fd!Z4d ee"e"f         d
e"fd"Z5	 d?d$ed%e j6        de"ded&e7d
e j         fd'Z8dej9        e j:        j;        d#fd$ed e"d%ee j6                 ded(ee<e j=        f         d&e7d
e j         fd)Z>de j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
e j         fd*Z?de j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
e j         fd+Z@	 d?d$ed,e j         d&e7d
ee"e"f         fd-ZA	 	 d@d$ed,ee j                  d&e7d
e"fd.ZB	 dAd$ed,ee j                  d
e"fd/ZC	 	 d@d$ed,ee j                  d&e7d
e"fd0ZDdejE        e j:        j;        fd$ed%ee j6                 d1ee"ef         d(ee<e j=        f         d
e j         f
d2ZFde j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
e j         fd3ZGde j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
e j         fd4ZHdejE        e j:        j;        fd$ed%ee j6                 d1ee"ef         d(ee<e j=        f         d
e j         f
d5ZIde j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
efd6ZJde j:        j;        fd$ed%ee j6                 d(ee<e j=        f         d
efd7ZKdej9        e j:        j;        fd$ed%ee j6                 ded(ee<e j=        f         d
ef
d8ZLdej9        e j:        j;        fd$ed%ee j6                 ded(ee<e j=        f         d
ef
d9ZMdej9        e j:        j;        fd$ed%ee j6                 ded(ee<e j=        f         d
ef
d:ZNdd#e j:        j;        fd$ed%ee j6                 d;e7d(ee<e j=        f         d
ef
d<ZOdejE        e j:        j;        fd$ed%ee j6                 d=ee"ef         d(ee<e j=        f         d
ee<e j         f         f
d>ZPdS )B    N)
acosasinatan2cosdegreesfabsradianssinsqrttan)DictOptionalTupleUnion)zoneinfo)
DepressionMinutesObserverSunDirection
TimePeriodnowrefraction_at_zenithtoday)	juliandayjulianday_to_juliancentury)sundawnsunrisenoonmidnightsunsetduskdaylightnighttwilight	blue_hourgolden_hour
rahukaalamzenithazimuth	elevationtime_at_elevationg?minutesreturnc                     t          | dz            }| |dz  z
  } | dz  } t          |           }| |z
  }t          |dz            }t          j        |||          S )zUConvert a floating point number of minutes to a
    :class:`~datetime.timedelta`
      <   i@B )dayssecondsmicroseconds)intdatetime	timedelta)r-   dssfracuss        I/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/astral/sun.pyminutes_to_timedeltar=   0   sj     	GdNAT"GlGGAaKE	UY		B1abAAAA    juliancenturyc                 (    d| dd| z  z   z  z   }|dz  S )z1Calculate the geometric mean longitude of the sungFvq@g/r@g3?     v@ )r?   l0s     r<   geom_mean_long_sunrD   >   s%    	]kI4M&MN	NB:r>   c                     d| dd| z  z
  z  z   S )z/Calculate the geometric mean anomaly of the sung<wXv@g*@g`P%$?rB   r?   s    r<   geom_mean_anomaly_sunrG   D   s    }i-6O(OPPPr>   c                     d| dd| z  z   z  z
  S )z+Calculate the eccentricity of Earth's orbitg]r?g_R
?g d`>rB   rF   s    r<   eccentric_location_earth_orbitrI   I   s    +}8T*TUUUr>   c                     t          |           }t          |          }t          |          }t          ||z             }t          ||z   |z             }|d| dd| z  z   z  z
  z  |dd| z  z
  z  z   |dz  z   }|S )z/Calculate the equation of the center of the sung5?gos?g_>Y1\>gy?gy?g,am2?)rG   r	   r
   )r?   mmradsinmsin2msin3mcs          r<   sun_eq_of_centerrQ   N   s    m,,A1::Dt99DtEtd"##E 	=Hx-7O,OPPQ
8h66
7	8
(
	  Hr>   c                 H    t          |           }t          |           }||z   S )z"Calculate the sun's true longitude)rD   rQ   )r?   rC   rP   s      r<   sun_true_longrS   `   s%    	M	*	*B''A6Mr>   c                 H    t          |           }t          |           }||z   S )z Calculate the sun's true anomaly)rG   rQ   )r?   rK   rP   s      r<   sun_true_anomolyrU   h   s%    m,,A''Aq5Lr>   c                     t          |           }t          |           }dd||z  z
  z  d|t          t          |                    z  z   z  S )NgemD ?   )rU   rI   r   r	   )r?   ves      r<   sun_rad_vectorrZ   p   sJ    ''A&}55A1q1u9%!a#gajj//.A*ABBr>   c                 z    t          |           }dd| z  z
  }|dz
  dt          t          |                    z  z
  S )N(\B_@C8@geNw?gNz1s?)rS   r
   r	   )r?   	true_longomegas      r<   sun_apparent_longr`   w   sA    m,,IX--Ew3wu~~+>+>!>>>r>   c                 F    d| d| d| dz  z
  z  z   z  z
  }dd|dz  z   dz  z   S )Ng r5@gQhG@g1ZGUC?gJE]?g      7@g      :@      N@rB   )r?   r3   s     r<   mean_obliquity_of_eclipticrc   ~   sE    }'MX,F"FGG G 47T>*d222r>   c                 t    t          |           }dd| z  z
  }|dt          t          |                    z  z   S )Nr\   r]   gh㈵d?)rc   r   r	   )r?   e0r_   s      r<   obliquity_correctionrf      s<    	#M	2	2BX--E#genn-----r>   c                 "   t          |           }t          |           }t          t          |                    t	          t          |                    z  }t          t          |                    }t          t          ||                    S )z#Calculate the sun's right ascension)rf   r`   r   r	   r
   r   r   )r?   ocaltananum	tanadenoms        r<   sun_rt_ascensionrl      sm    	m	,	,B	=	)	)B'"++WR[[!1!11GGBKK  I5),,---r>   c                     t          |           }t          |           }t          t          |                    t          t          |                    z  }t	          t          |                    S )zCalculate the sun's declination)rf   r`   r
   r	   r   r   )r?   rY   lambdsints       r<   sun_declinationrp      sT    ]++Am,,Ewqzz??S000D4::r>   c                 h    t          |           }t          t          |          dz            }||z  S )N       @)rf   r   r	   )r?   epsilonys      r<   var_yru      s2    "=11GGGs"##Aq5Lr>   c                 8   t          |           }t          |           }t          |           }t          |           }t	          dt          |          z            }t	          t          |                    }t          dt          |          z            }t	          dt          |          z            }t	          dt          |          z            }	||z  d|z  |z  z
  d|z  |z  |z  |z  z   d|z  |z  |z  z
  d|z  |z  |	z  z
  }
t          |
          dz  S )Nrr         @      ?g      ?)rD   rI   rG   ru   r
   r	   r   r   )r?   rC   rY   rK   rt   sin2l0rM   cos2l0sin4l0rN   Etimes              r<   
eq_of_timer}      s    	M	*	*B&}55Am,,AmAwr{{"##Fwqzz??Dwr{{"##Fwr{{"##Fgajj !!E 	
F

'D.	
'A+
v
%	& 'A+
	 (Q,
		 
 5>>Cr>   latitudedeclinationr)   	directionc                 B   t          |           }t          |          }t          |          }t          |          t          |          t          |          z  z
  t          |          t          |          z  z  }t          |          }|t          j        k    r| }|S )aZ  Calculate the hour angle of the sun

    See https://en.wikipedia.org/wiki/Hour_angle#Solar_hour_angle

    Args:
        latitude: The latitude of the obersver
        declination: The declination of the sun
        zenith: The zenith angle of the sun
        direction: The direction of traversal of the sun

    Raises:
        ValueError
    )r	   r   r
   r   r   SETTING)	r~   r   r)   r   latitude_raddeclination_rad
zenith_radh
hour_angles	            r<   r   r      s    " 8$$Lk**OJ	Z3|,,s?/C/CC	CLC000	A aJL((( [
r>   r+   c                 f    | dk    rdS d}|}|| z   }t          ||z            }t          |          S )a  Calculate the extra degrees of depression that you can see round the earth
    due to the increase in elevation.

    Args:
        elevation: Elevation above the earth in metres

    Returns:
        A number of degrees to add to adjust for the elevation of the observer
    r   i` )r   r   )r+   ra1h1theta1s        r<   adjust_to_horizonr      s@     A~~qA	
B	
YB"r']]F6??r>   c                    | d         dk    rdS | d         dk     rdnd}|t          t          t          | d                   t          t	          | d         d          t	          | d         d          z             z                      z  S )zBCalculate the number of degrees to adjust for an obscuring featurer           rW      )r   r   r   r   pow)r+   signs     r<   adjust_to_obscuring_featurer      s    |ss1##22D'T)A,$s9Q<';';c)A,PQ>R>R'R"S"SSTT   r>   Tobserverdatewith_refractionc                 J   | j         dk    rd}n| j         dk     rd}n| j         }d}t          | j        t                    r | j        dk    rt	          | j                  }n.t          | j        t
                    rt          | j                  }|rt          ||z             }nd}t          |          }d}	d}
t          d          D ]}t          ||	z             }t          |          }t          ||||z   |z   |          }| j         t          |          z
  }t          |          }|dz  |z
  }|dk     r|dz  }d|z   }
|
d	z  }	t!          |
          }t#          j        |j        |j        |j                  |z   }|                    t"          j        j        
          }|S )a  Calculate the time in the UTC timezone when the sun transits the
    specificed zenith

    Args:
        observer: An observer viewing the sun at a specific, latitude, longitude
            and elevation
        date: The date to calculate for
        zenith: The zenith angle for which to calculate the transit time
        direction: The direction that the sun is traversing

    Raises:
        ValueError if the zenith is not transitted by the sun

    Returns:
        the time when the sun transits the specificed zenith
    33333sV@33333sVr   r   rw   g     r0        @g     @tzinfo)r~   
isinstancer+   floatr   tupler   r   r   ranger   rp   r   	longituder   r}   r=   r6   yearmonthdayreplacetimezoneutc)r   r   r)   r   r   r~   adjustment_for_elevationadjustment_for_refractionjd
adjustmenttimeUTC_jcr   	hourangledeltaeqtimeoffsettddts                       r<   time_of_transitr      s   . 4		U	"	"$"($e,, S1Cc1I1I#4X5G#H#H  	H&	.	. S#>x?Q#R#R  ($8--%
 %
!! %(!	4BJG1XX & &'Z88%b))--0II	
 
	 ##gi&8&88Bv%F??dNF&.v%

	g	&	&B		49dj$(	;	;b	@B	8,0	1	1BIr>   r   c                 l   |dk    rd|z
  }t           j        }t          |t                    rt	          j        |          }|t          |          }d|z
  }	 t          | ||||                              |          S # t          $ r+}|j
        d         dk    rt          d| d          | d}~ww xY w)	a  Calculates the time when the sun is at the specified elevation on the
    specified date.

    Note:
        This method uses positive elevations for those above the horizon.

        Elevations greater than 90 degrees are converted to a setting sun
        i.e. an elevation of 110 will calculate a setting sun at 70 degrees.

    Args:
        elevation: Elevation of the sun in degrees above the horizon to calculate for.
        observer:  Observer to calculate for
        date:      Date to calculate for. Default is today's date in the timezone
                   `tzinfo`.
        direction: Determines whether the calculated time is for the sun rising
                   or setting.
                   Use ``SunDirection.RISING`` or ``SunDirection.SETTING``.
                   Default is rising.
        tzinfo:    Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which the sun is at the specified elevation.
         V@     f@NZ   r   math domain errorz"Sun never reaches an elevation of z degrees at this location.)r   r   r   strr   ZoneInfor   r   
astimezone
ValueErrorargs)r   r+   r   r   r   r   r)   excs           r<   r,   r,   H  s    @ 4I%	 (	&# +"6**|V}})^FdFI
 

*
 
	

    8A;---$Y $ $ $  
 s   %A> >
B3&B..B3c           	         t          |t                    rt          j        |          }|t	          |          }t          t          |                    }t          |          }dd| j        z  z
  |z
  dz  }t          |          }t          ||z
  dz            }t          ||z
  dz  |z
  dz            }|dk    r|dz  }|dz  }n|dk     r
|dz  }|dz  }|dk    r|dz  }|dz  }n|dk     r
|dz  }|dz  }|d	k    r|d
z  }|t          j        d          z  }n#|dk     r|d
z  }|t          j        d          z  }t          j
        |j        |j        |j        |||t          j        j                  }	|	                    |          S )a  Calculate solar noon time when the sun is at its highest point.

    Args:
        observer: An observer viewing the sun at a specific, latitude, longitude
                  and elevation
        date:     Date to calculate for. Default is today for the specified tzinfo.
        tzinfo:   Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which noon occurs.
    Nr      rb   r1   ;   rW   r         r2   r   )r   r   r   r   r   r   r   r}   r   r5   r6   r7   r   r   r   r   r   r   )
r   r   r   r   r   r   hourminutesecondr   s
             r<   r   r     s     &# +"6**|V}}	#IdOO	4	4B^^FH../&8D@Gw<<D'D.B&''FGdNb(F2b899F{{"!	!"!{{"		!"	byy
"****	
"****	
 $  D ??6"""r>   c           	      `   t          |t                    rt          j        |          }|t	          |          }t          j        ddd          }t          t
          j                            ||                    }t          |dz   | j
         dz  z             }t          |          }| j
         dz  |z
  }|dz  }t          |          }t          ||z
  dz            }	t          ||z
  dz  |	z
  dz            }
|
d	k    r|
dz  }
|	d
z  }	n|
dk     r
|
dz  }
|	d
z  }	|	d	k    r|	dz  }	|d
z  }n|	dk     r
|	dz  }	|d
z  }|dk     r|dz  }|t          j        d
          z  }t          j        |j        |j        |j        ||	|
t
          j        j                  }|                    |          S )a  Calculate solar midnight time.

    Note:
        This calculates the solar midnight that is closest
        to 00:00:00 of the specified date i.e. it may return a time that is on
        the previous day.

    Args:
        observer: An observer viewing the sun at a specific, latitude, longitude
                  and elevation
        date:     Date to calculate for. Default is today for the specified tzinfo.
        tzinfo:   Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which midnight occurs.
    N   r   rx   rA   rw   rb   r1   r   rW   r   r   r   )r   r   r   r   r   r6   timer   combiner   r   r}   r5   r7   r   r   r   r   r   r   )r   r   r   middayr   newtr   r   r   r   r   r    s               r<   r    r      s   * &# +"6**|V}}]2q!$$F	8$,,T6::	;	;B%b3h(2D1Du1L&LMMDF""S(F2GnGw<<D'D.B&''FGdNb(F2b899F{{"!	!"!{{"		!"	axx
"**** 	
 $  H v&&&r>   dateandtimec                 L   | j         dk    rd}n| j         dk     rd}n| j         }| j        }|j        d}|}nN|                                                                 dz  }|                    t          j        j                  }t          |          }t          |          }t          |          }	t          |          }
|
d|z  z   d|z  z   }|j        dz  |j        z   |j        dz  z   |z   }|dk    r|dz
  }|dk    |dz  d	z
  }|d
k     r|dz   }t!          t#          |                    }t!          t#          |                    }t%          t#          |                    }t%          t#          |	                    }t!          t#          |	                    }||z  |z  ||z  z   }|dk    rd}n|dk     rd}t'          t)          |                    }|t%          t#          |                    z  }t+          |          dk    rl|t!          t#          |                    z  |z
  |z  }t+          |          dk    r|dk     rd}nd}d	t'          t)          |                    z
  }|dk    r| }n|dk    rd	}nd}|dk     r|dz   }|r|t-          |          z  }||fS )Nr   r   r   g      @rw   r1   rb   r0   r   iLrA   g      ?g      gMbP?r   )r~   r   r   	utcoffsettotal_secondsr   r6   r   r   r   r   rp   r}   r   r   r   r   r	   r
   r   r   absr   )r   r   r   r~   r   zoneutc_datetimer   tr   r   solarTimeFixtrueSolarTimer   chclslsdcdcszr)   azDenomazRadr*   s                           r<   zenith_and_azimuthr     s   
 4		U	"	"$"I!"%%''55777&@"--h.?.CDD	<	 	 B"2&&A!!$$K]]F S9_-d;L4

	

t
#	$ 	  $

%, $

 #e+I4%		WY	 	 B	WX		B	WX		B	W[!!	"	"B	W[!!	"	"B
r'B,b
 C
Syy	tT#YYF3wv'''G
7||es76??+++r1W<u::qyy'$u++...s??hGc>>GGG}}E/ /&v... 7?r>   c                 p    |t          t          j        j                  }t	          | ||          d         S )a  Calculate the zenith angle of the sun.

    Args:
        observer:    Observer to calculate the solar zenith for
        dateandtime: The date and time for which to calculate the angle.
                     If `dateandtime` is None or is a naive Python datetime
                     then it is assumed to be in the UTC timezone.
        with_refraction: If True adjust zenith to take refraction into account

    Returns:
        The zenith angle in degrees.
    Nr   r   r6   r   r   r   r   r   r   s      r<   r)   r)   b  s4    $ (+/00h_EEaHHr>   c                 n    |t          t          j        j                  }t	          | |          d         S )a  Calculate the azimuth angle of the sun.

    Args:
        observer:    Observer to calculate the solar azimuth for
        dateandtime: The date and time for which to calculate the angle.
                     If `dateandtime` is None or is a naive Python datetime
                     then it is assumed to be in the UTC timezone.

    Returns:
        The azimuth angle in degrees clockwise from North.

    If `dateandtime` is a naive Python datetime then it is assumed to be
    in the UTC timezone.
    NrW   r   )r   r   s     r<   r*   r*   z  s2    & (+/00h44Q77r>   c                 j    |t          t          j        j                  }dt	          | ||          z
  S )a  Calculate the sun's angle of elevation.

    Args:
        observer:    Observer to calculate the solar elevation for
        dateandtime: The date and time for which to calculate the angle.
                     If `dateandtime` is None or is a naive Python datetime
                     then it is assumed to be in the UTC timezone.
        with_refraction: If True adjust elevation to take refraction into account

    Returns:
        The elevation angle in degrees above the horizon.
    Nr   )r   r6   r   r   r)   r   s      r<   r+   r+     s4    $ (+/00&;@@@@r>   
depressionc                 X   t          |t                    rt          j        |          }|t	          |          }n7t          |t
          j                  r|j        p|}|                                }d}t          |t                    r|j	        }n|}	 t          | |d|z   t          j                                      |          }|                                }||k    r||k     rt          j        d          }nt          j        d          }||z   }t          | |d|z   t          j                                      |          }|                                }||k    rt          d          |S # t          $ r+}	|	j        d         d	k    rt          d
| d          |	 d}	~	ww xY w)a  Calculate dawn time.

    Args:
        observer:   Observer to calculate dawn for
        date:       Date to calculate for. Default is today's date in the
                    timezone `tzinfo`.
        depression: Number of degrees below the horizon to use to calculate dawn.
                    Default is for Civil dawn i.e. 6.0
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which dawn occurs.

    Raises:
        ValueError: if dawn does not occur on the specified date
    Nr   r   rW   r   r   z0Unable to find a dawn time on the date specifiedr   r   Sun never reaches - degrees below the horizon, at this location.)r   r   r   r   r   r6   r   r   r   valuer   r   RISINGr   r7   r   r   
r   r   r   r   deptottot_dater   new_dater   s
             r<   r   r     s   , &# +"6**|V}}	D(+	,	, &yy{{C*j)) #dD3J(;
 

*
 
 	 88::t$ *222 *333e|H!s
#	 
 j   xxzzH4 !STTT
   8A;---WSWWW     CE4 4
F)>&F$$F)c                 t   t          |t                    rt          j        |          }|t	          |          }n7t          |t
          j                  r|j        p|}|                                }	 t          | |dt          z   t          j                                      |          }|                                }||k    r||k     rt          j        d          }nt          j        d          }||z   }t          | |dt          z   t          j                                      |          }|                                }||k    rt          d          |S # t          $ rP}|j        d         dk    r9t!          | t#          | |                    }|dk    rd	}	nd
}	t          |	          | d}~ww xY w)a  Calculate sunrise time.

    Args:
        observer: Observer to calculate sunrise for
        date:     Date to calculate for. Default is today's date in the
                  timezone `tzinfo`.
        tzinfo:   Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which sunrise occurs.

    Raises:
        ValueError: if the sun does not reach the horizon on the specified date
    Nr   rW   r   r   z3Unable to find a sunrise time on the date specifiedr   r   >Sun is always below the horizon on this day, at this location.>Sun is always above the horizon on this day, at this location.)r   r   r   r   r   r6   r   r   r   SUN_APPARENT_RADIUSr   r   r   r7   r   r   r)   r   
r   r   r   r   r   r   r   r   zmsgs
             r<   r   r     s   & &# +"6**|V}}	D(+	,	, &yy{{'&&	
 

 *
 
 	 88::t$ *222 *333e|H!**#	 
 j   xxzzH4 !VWWW
 	 	 	8A;---xh!5!566A4xxVVS//s*	   4C(E 
F7'AF22F7c                 t   t          |t                    rt          j        |          }|t	          |          }n7t          |t
          j                  r|j        p|}|                                }	 t          | |dt          z   t          j                                      |          }|                                }||k    r||k     rt          j        d          }nt          j        d          }||z   }t          | |dt          z   t          j                                      |          }|                                }||k    rt          d          |S # t          $ rP}|j        d         dk    r9t!          | t#          | |                    }|dk    rd	}	nd
}	t          |	          | d}~ww xY w)a  Calculate sunset time.

    Args:
        observer: Observer to calculate sunset for
        date:     Date to calculate for. Default is today's date in the
                  timezone `tzinfo`.
        tzinfo:   Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which sunset occurs.

    Raises:
        ValueError: if the sun does not reach the horizon
    Nr   rW   r   r   z2Unable to find a sunset time on the date specifiedr   r   r   r   )r   r   r   r   r   r6   r   r   r   r   r   r   r   r7   r   r   r)   r   r   s
             r<   r!   r!   <  s   ( &# +"6**|V}}	D(+	,	, &yy{{'&& 	
 

 *
 
 	 88::t$ *222 *333e|H!**$	 
 j   xxzzH4 !UVVV
 	 	 	8A;---xh!5!566A4xxVVS//s*	r   c                 X   t          |t                    rt          j        |          }|t	          |          }n7t          |t
          j                  r|j        p|}|                                }d}t          |t                    r|j	        }n|}	 t          | |d|z   t          j                                      |          }|                                }||k    r||k     rt          j        d          }nt          j        d          }||z   }t          | |d|z   t          j                                      |          }|                                }||k    rt          d          |S # t          $ r+}	|	j        d         d	k    rt          d
| d          |	 d}	~	ww xY w)a  Calculate dusk time.

    Args:
        observer:   Observer to calculate dusk for
        date:       Date to calculate for. Default is today's date in the
                    timezone `tzinfo`.
        depression: Number of degrees below the horizon to use to calculate dusk.
                    Default is for Civil dusk i.e. 6.0
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        Date and time at which dusk occurs.

    Raises:
        ValueError: if dusk does not occur on the specified date
    Nr   r   rW   r   r   z0Unable to find a dusk time on the date specifiedr   r   r   r   )r   r   r   r   r   r6   r   r   r   r   r   r   r   r   r7   r   r   r   s
             r<   r"   r"     s   . &# +"6**|V}}	D(+	,	, &yy{{C*j)) !dD3J(<
 

*
 
 	 88::t$ *222 *333e|H!s
$	 
 j   xxzzH4 !STTT
   8A;---WSWWW  r   c                     t          |t                    rt          j        |          }|t	          |          }t          | ||          }t          | ||          }||fS )a  Calculate daylight start and end times.

    Args:
        observer:   Observer to calculate daylight for
        date:       Date to calculate for. Default is today's date in the
                    timezone `tzinfo`.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        A tuple of the date and time at which daylight starts and ends.

    Raises:
        ValueError: if the sun does not rise or does not set
    )r   r   r   r   r   r   r!   )r   r   r   srsss        r<   r#   r#     sa    & &# +"6**|V}}	4	(	(B	$	'	'Br6Mr>   c                     t          |t                    rt          j        |          }|t	          |          }t          | |d|          }|t          j        d          z   }t          | |d|          }||fS )af  Calculate night start and end times.

    Night is calculated to be between astronomical dusk on the
    date specified and astronomical dawn of the next day.

    Args:
        observer:   Observer to calculate night for
        date:       Date to calculate for. Default is today's date for the
                    specified tzinfo.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        A tuple of the date and time at which night starts and ends.

    Raises:
        ValueError: if dawn does not occur on the specified date or
                    dusk on the following day
    N   rW   r   )	r   r   r   r   r   r"   r6   r7   r   )r   r   r   starttomorrowends         r<   r$   r$     s~    . &# +"6**|V}}4F++Eh(a0000H
x1f
-
-C#:r>   c                    t          |t                    rt          j        |          }|t	          |          }t          | |d|                              |          }|t          j        k    r%t          | ||                              |          }n$t          | ||                              |          }|t          j        k    r||fS ||fS )aB  Returns the start and end times of Twilight
    when the sun is traversing in the specified direction.

    This method defines twilight as being between the time
    when the sun is at -6 degrees and sunrise/sunset.

    Args:
        observer:   Observer to calculate twilight for
        date:       Date for which to calculate the times.
                    Default is today's date in the timezone `tzinfo`.
        direction:  Determines whether the time is for the sun rising or setting.
                    Use ``astral.SunDirection.RISING`` or
                    ``astral.SunDirection.SETTING``.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        A tuple of the date and time at which twilight starts and ends.

    Raises:
        ValueError: if the sun does not rise or does not set
    N`   )r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   r  r  s         r<   r%   r%     s    8 &# +"6**|V}}HdFI??JJ E L'''hf--88@@XtV,,77??L'''czEzr>   c                 :   t          |t                    rt          j        |          }|t	          |          }t          | |d|                              |          }t          | |d|                              |          }|t          j        k    r||fS ||fS )as  Returns the start and end times of the Golden Hour
    when the sun is traversing in the specified direction.

    This method uses the definition from PhotoPills i.e. the
    golden hour is when the sun is between 4 degrees below the horizon
    and 6 degrees above.

    Args:
        observer:   Observer to calculate the golden hour for
        date:       Date for which to calculate the times.
                    Default is today's date in the timezone `tzinfo`.
        direction:  Determines whether the time is for the sun rising or setting.
                    Use ``SunDirection.RISING`` or ``SunDirection.SETTING``.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        A tuple of the date and time at which the Golden Hour starts and ends.

    Raises:
        ValueError: if the sun does not transit the elevations -4 & +6 degrees
    N^   T   	r   r   r   r   r   r   r   r   r   r	  s         r<   r'   r'   @  s    8 &# +"6**|V}}HdFI??JJ E (D&)
=
=
H
H C L'''czEzr>   c                 :   t          |t                    rt          j        |          }|t	          |          }t          | |d|                              |          }t          | |d|                              |          }|t          j        k    r||fS ||fS )aY  Returns the start and end times of the Blue Hour
    when the sun is traversing in the specified direction.

    This method uses the definition from PhotoPills i.e. the
    blue hour is when the sun is between 6 and 4 degrees below the horizon.

    Args:
        observer:   Observer to calculate the blue hour for
        date:       Date for which to calculate the times.
                    Default is today's date in the timezone `tzinfo`.
        direction:  Determines whether the time is for the sun rising or setting.
                    Use ``SunDirection.RISING`` or ``SunDirection.SETTING``.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        A tuple of the date and time at which the Blue Hour starts and ends.

    Raises:
        ValueError: if the sun does not transit the elevations -4 & -6 degrees
    Nr  r  r  r	  s         r<   r&   r&   o  s    6 &# +"6**|V}}HdFI??JJ E (D&)
=
=
H
H C L'''czEzr>   daytimec                    t          |t                    rt          j        |          }|t	          |          }|r#t          | ||          }t          | ||          }n:t          | ||          }t          j        d          }t          | ||z   |          }t          j        ||z
  j	        dz            }g d}|
                                }	||	         }
|||
z  z   }||z   }||fS )a  Calculate ruhakaalam times.

    Args:
        observer:   Observer to calculate rahukaalam for
        date:       Date to calculate for. Default is today's date in the
                    timezone `tzinfo`.
        daytime:    If True calculate for the day time else calculate for the
                    night time.
        tzinfo:     Timezone to return times in. Default is UTC.

    Returns:
        Tuple containing the start and end times for Rahukaalam.

    Raises:
        ValueError: if the sun does not rise or does not set
    NrW   r      )r3   )rW   r  r         r      )r   r   r   r   r   r   r!   r6   r7   r3   weekday)r   r   r  r   r  r  onedayoctant_durationoctant_indexr  octants              r<   r(   r(     s   . &# +"6**|V}} 7$//XtV,,xv..#+++hvv66(#+1F1JKKKO )((LllnnG'"F_v-.E
/
!C#:r>   dawn_dusk_depressionc           
          t          |t                    rt          j        |          }|t	          |          }t          | |||          t          | ||          t          | ||          t          | ||          t          | |||          dS )a  Calculate all the info for the sun at once.

    Args:
        observer:             Observer for which to calculate the times of the sun
        date:                 Date to calculate for.
                              Default is today's date in the timezone `tzinfo`.
        dawn_dusk_depression: Depression to use to calculate dawn and dusk.
                              Default is for Civil dusk i.e. 6.0
        tzinfo:               Timezone to return times in. Default is UTC.

    Returns:
        Dictionary with keys ``dawn``, ``sunrise``, ``noon``, ``sunset`` and ``dusk``
        whose values are the results of the corresponding functions.

    Raises:
        ValueError: if passed through from any of the functions
    N)r   r   r   r!   r"   )
r   r   r   r   r   r   r   r   r!   r"   )r   r   r  r   s       r<   r   r     s    0 &# +"6**|V}} Xt%96BB8T622XtV,,400Xt%96BB  r>   )T)NT)N)Qr6   mathr   r   r   r   r   r   r	   r
   r   r   typingr   r   r   r   r   ImportError	backportsastralr   r   r   r   r   r   r   r   astral.julianr   r   __all__r   r   r7   r=   rD   rG   rI   rQ   rS   rU   rZ   r`   rc   rf   rl   rp   ru   r}   r   r   r   r   boolr   r   r   r   r   r   r,   r   r    r   r)   r*   r+   CIVILr   r   r!   r"   r#   r$   r%   r'   r&   r(   r   rB   r>   r<   <module>r%     s    O O O O O O O O O O O O O O O O O O O O O O O O / / / / / / / / / / / /#OOOO # # #""""""""#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 @ ? ? ? ? ? ? ?  , * B% BH,> B B B Be     Q Q5 Q Q Q Q
V% VE V V V V
E e    $ 5    E e    C% CE C C C C?U ?u ? ? ? ?3e 3 3 3 3 3. .% . . . ..E .e . . . .5 U     5     e          0"'16CO
   > 5    *5+> 5      !H HH
-H H 	H
 H H H H H\ %)*1*2*;*? 8 888 8=
!8 	8
 #x&'8 8 8 8 8 8z %)*2*;*?<# <#<#
8=
!<# #x&'<# 	<# <# <# <#B %)*2*;*?B' B'B'
8=
!B' #x&'B' 	B' B' B' B'P !X XX"X X 5%<	X X X Xz 04 I II(+,I I 	I I I I4 048 88(+,8 8 8 8 86 04 A AA(+,A A 	A A A A4 %)+5+;*2*;*?	H HH
8=
!H eZ'(H #x&'	H
 H H H HZ %)*2*;*?C CC
8=
!C #x&'C 	C C C CP %)*2*;*?D DD
8=
!D #x&'D 	D D D DR %)+5+;*2*;*?	G GG
8=
!G eZ'(G #x&'	G
 G G G GX %)*2*;*? 
8=
! #x&' 	   B %)*2*;*?! !!
8=
!! #x&'! 	! ! ! !L %)*1*2*;*?	- --
8=
!- - #x&'	-
 - - - -d %)*1*2*;*?	, ,,
8=
!, , #x&'	,
 , , , ,b %)*1*2*;*?	+ ++
8=
!+ + #x&'	+
 + + + +` %)*2*;*?	0 00
8=
!0 0 #x&'	0
 0 0 0 0j %)5?5E*2*;*?	$ $$
8=
!$  z 12$ #x&'	$
 
#x 
 !$ $ $ $ $ $s   / ==