.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DateTime::Event::Sunrise 3pm" .TH DateTime::Event::Sunrise 3pm "2022-08-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DateTime::Event::Sunrise \- Perl DateTime extension for computing the sunrise/sunset on a given day .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use DateTime; \& use DateTime::Event::Sunrise; \& \& # generating DateTime objects from a DateTime::Event::Sunrise object \& my $sun_Kyiv = DateTime::Event::Sunrise\->new(longitude => +30.85, # 30°51\*(AqE \& latitude => +50.45); # 50°27\*(AqN \& for (12, 13, 14) { \& my $dt_yapc_eu = DateTime\->new(year => 2013, \& month => 8, \& day => $_, \& time_zone => \*(AqEurope/Kiev\*(Aq); \& say "In Kyiv (50°27\*(AqN, 30°51\*(AqE) on ", $dt_yapc_eu\->ymd, " sunrise occurs at ", $sun_Kyiv\->sunrise_datetime($dt_yapc_eu)\->hms, \& " and sunset occurs at ", $sun_Kyiv\->sunset_datetime ($dt_yapc_eu)\->hms; \& } \& \& # generating DateTime objects from DateTime::Set objects \& my $sunrise_Austin = DateTime::Event::Sunrise\->sunrise(longitude => \-94.73, # 97°44\*(AqW \& latitude => +30.3); # 30°18\*(AqN \& my $sunset_Austin = DateTime::Event::Sunrise\->sunset (longitude => \-94.73, \& latitude => +30.3); \& my $dt_yapc_na_rise = DateTime\->new(year => 2013, \& month => 6, \& day => 3, \& time_zone => \*(AqAmerica/Chicago\*(Aq); \& my $dt_yapc_na_set = $dt_yapc_na_rise\->clone; \& say "In Austin (30°18\*(AqN, 97°44\*(AqW), sunrises and sunsets are"; \& for (1..3) { \& $dt_yapc_na_rise = $sunrise_Austin\->next($dt_yapc_na_rise); \& $dt_yapc_na_set = $sunset_Austin \->next($dt_yapc_na_set); \& say $dt_yapc_na_rise, \*(Aq \*(Aq, $dt_yapc_na_set; \& } \& \& # If you deal with a polar location \& my $sun_in_Halley = DateTime::Event::Sunrise\->new( \& longitude => \-26.65, # 26°39\*(AqW \& latitude => \-75.58, # 75°35\*(AqS \& precise => 1, \& ); \& my $Alex_arrival = DateTime\->new(year => 2006, # approximate date, not necessarily the exact one \& month => 1, \& day => 15, \& time_zone => \*(AqAntarctica/Rothera\*(Aq); \& say $Alex_arrival\->strftime("Alex Gough (a Perl programmer) arrived at Halley Base on %Y\-%m\-%d."); \& if ($sun_in_Halley\->is_polar_day($Alex_arrival)) { \& say "It would be days, maybe weeks, before the sun would set."; \& } \& elsif ($sun_in_Halley\->is_polar_night($Alex_arrival)) { \& say "It would be days, maybe weeks, before the sun would rise."; \& } \& else { \& my $sunset = $sun_in_Halley\->sunset_datetime($Alex_arrival); \& say $sunset\->strftime("And he saw his first antarctic sunset at %H:%M:%S."); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module will computes the time of sunrise and sunset for a given date and a given location. The computation uses Paul Schlyter's algorithm. .PP Actually, the module creates a DateTime::Event::Sunrise object or a DateTime::Set object, which are used to generate the sunrise or the sunset times for a given location and for any date. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" This is the DateTime::Event::Sunrise constructor. It takes keyword parameters, which are: .IP "longitude" 4 .IX Item "longitude" This is the longitude of the location where the sunrises and sunsets are observed. It is given as decimal degrees: no minutes, no seconds, but tenths and hundredths of degrees. Another break with the normal usage is that Eastern longitude are positive, Western longitudes are negative. .Sp Default value is 0, that is Greenwich or any location on the eponymous meridian. .IP "latitude" 4 .IX Item "latitude" This is the latitude of the location where the sunrises and sunsets are observed. As for the longitude, it is given as decimal degrees. Northern latitudes are positive numbers, Southern latitudes are negative numbers. .Sp Default value is 0, that is any location on the equator. .IP "altitude" 4 .IX Item "altitude" This is the height of the Sun at sunrise or sunset. In astronomical context, the altitude or height is the angle between the Sun and the local horizon. It is expressed as degrees, usually with a negative number, since the Sun is \fIbelow\fR the horizon. .Sp Default value is \-0.833, that is when the sun's upper limb touches the horizon, while taking in account the light refraction. .Sp Positive altitude are allowed, in case the location is near a mountain range behind which the sun rises or sets. .IP "precise" 4 .IX Item "precise" Boolean to control which algorithm is used. A false value gives a simple algorithm, but which can lead to inaccurate sunrise times and sunset times. A true value gives a more elaborate algorithm, with a loop to refine the sunrise and sunset times and obtain a better precision. .Sp Default value is 0, to choose the simple algorithm. .Sp This parameter replaces the \f(CW\*(C`iteration\*(C'\fR deprecated parameter. .IP "upper_limb" 4 .IX Item "upper_limb" Boolean to choose between checking the Sun's upper limb or its center. A true value selects the upper limb, a false value selects the center. .Sp This parameter is significant only when the altitude does not already deal with the sun radius. When the altitude takes into account the sun radius, this parameter should be false. .Sp Default value is 0, since the upper limb correction is already taken in account with the default \-0.833 altitude. .IP "silent" 4 .IX Item "silent" Boolean to control the output of some warning messages. With polar locations and dates near the winter solstice or the summer solstice, it may happen that the sun never rises above the horizon or never sets below. If this parameter is set to false, the module will send warnings for these conditions. If this parameter is set to true, the module will not pollute your \fI\s-1STDERR\s0\fR stream. .Sp Default value is 0, for backward compatibility. .IP "trace" 4 .IX Item "trace" This parameter should either be a false value or a filehandle opened for output. In the latter case, a few messages are printed to the filehandle, which allows the programmer to see step by step how the sunrise and the sunset are computed. .Sp Used for analysis and debugging purposes. You need to read the text \&\fIdoc/astronomical\-notes.pod\fR in the sister module Astro::Sunrise to understand what the traced values represent. .Sp Default value is \f(CW0\fR, which does not produce trace messages. .SS "sunrise, sunset" .IX Subsection "sunrise, sunset" Although they come from the DateTime::Event::Sunrise module, these methods are \f(CW\*(C`DateTime::Set\*(C'\fR constructors. They use the same parameters as the \f(CW\*(C`new\*(C'\fR constructor, but they give objects from a different class. .SS "sunrise_datetime, sunset_datetime" .IX Subsection "sunrise_datetime, sunset_datetime" These two methods apply to \f(CW\*(C`DateTime::Event::Sunrise\*(C'\fR objects (that is, created with \f(CW\*(C`new\*(C'\fR, not \f(CW\*(C`sunrise\*(C'\fR or \f(CW\*(C`sunset\*(C'\fR). They receive one parameter in addition to \f(CW$self\fR, a \f(CW\*(C`DateTime\*(C'\fR object. They return another \f(CW\*(C`DateTime\*(C'\fR object, for the same day, but with the time of the sunrise or sunset, respectively. .SS "sunrise_sunset_span" .IX Subsection "sunrise_sunset_span" This method applies to \f(CW\*(C`DateTime::Event::Sunrise\*(C'\fR objects. It accepts a \&\f(CW\*(C`DateTime\*(C'\fR object as the second parameter. It returns a \f(CW\*(C`DateTime::Span\*(C'\fR object, beginning at sunrise and ending at sunset. .SS "is_polar_night, is_polar_day, is_day_and_night" .IX Subsection "is_polar_night, is_polar_day, is_day_and_night" These methods apply to \f(CW\*(C`DateTime::Event::Sunrise\*(C'\fR objects. They accept a \&\f(CW\*(C`DateTime\*(C'\fR object as the second parameter. They return a boolean indicating the following condutions: .IP "\(bu" 4 is_polar_night is true when the sun stays under the horizon. Or rather under the altitude parameter used when the \f(CW\*(C`DateTime::Event::Sunrise\*(C'\fR object was created. .IP "\(bu" 4 is_polar_day is true when the sun stays above the horizon, resulting in a \*(L"Midnight sun\*(R". Or rather when it stays above the altitude parameter used when the \f(CW\*(C`DateTime::Event::Sunrise\*(C'\fR object was created. .IP "\(bu" 4 is_day_and_night is true when neither is_polar_day, nor is_polar_night are true. .SS "next current previous contains as_list iterator" .IX Subsection "next current previous contains as_list iterator" See DateTime::Set. .SH "EXTENDED EXAMPLES" .IX Header "EXTENDED EXAMPLES" .Vb 4 \& my $dt = DateTime\->new( year => 2000, \& month => 6, \& day => 20, \& ); \& \& my $sunrise = DateTime::Event::Sunrise \->sunrise ( \& longitude =>\*(Aq\-118\*(Aq, \& latitude =>\*(Aq33\*(Aq, \& altitude => \*(Aq\-0.833\*(Aq, \& precise => \*(Aq1\*(Aq \& ); \& \& my $sunset = DateTime::Event::Sunrise \->sunset ( \& longitude =>\*(Aq\-118\*(Aq, \& latitude =>\*(Aq33\*(Aq, \& altitude => \*(Aq\-0.833\*(Aq, \& precise => \*(Aq1\*(Aq \& ); \& \& my $tmp_rise = $sunrise\->next( $dt ); \& \& my $dt2 = DateTime\->new( year => 2000, \& month => 12, \& day => 31, \& ); \& \& # iterator \& my $dt_span = DateTime::Span\->new( start =>$dt, end=>$dt2 ); \& my $set = $sunrise\->intersection($dt_span); \& my $iter = $set\->iterator; \& while ( my $dt = $iter\->next ) { \& print \*(Aq \*(Aq,$dt\->datetime; \& } \& \& # is it day or night? \& my $day_set = DateTime::SpanSet\->from_sets( \& start_set => $sunrise, end_set => $sunset ); \& print $day_set\->contains( $dt ) ? \*(Aqday\*(Aq : \*(Aqnight\*(Aq; \& \& my $dt = DateTime\->new( year => 2000, \& month => 6, \& day => 20, \& time_zone => \*(AqAmerica/Los_Angeles\*(Aq, \& ); \& \& my $sunrise = DateTime::Event::Sunrise \->new( \& longitude =>\*(Aq\-118\*(Aq , \& latitude => \*(Aq33\*(Aq, \& altitude => \*(Aq\-0.833\*(Aq, \& precise => \*(Aq1\*(Aq \& \& ); \& \& my $tmp = $sunrise\->sunrise_sunset_span($dt); \& print "Sunrise is:" , $tmp\->start\->datetime , "\en"; \& print "Sunset is:" , $tmp\->end\->datetime; .Ve .SH "NOTES" .IX Header "NOTES" .SS "Longitude Signs" .IX Subsection "Longitude Signs" Remember, contrary to the usual convention, .PP \&\s-1EASTERN\s0 longitudes are \s-1POSITIVE,\s0 .PP \&\s-1WESTERN\s0 longitudes are \s-1NEGATIVE.\s0 .PP On the other hand, the latitude signs follow the usual convention: .PP Northen latitudes are positive, .PP Southern latitudes are negative. .SS "Sun Height" .IX Subsection "Sun Height" There are a number of sun heights to choose from. The default is \&\-0.833 because this is what most countries use. Feel free to specify it if you need to. Here is the list of values to specify the sun height with: .IP "\(bu" 4 \&\fB0\fR degrees .Sp Center of Sun's disk touches a mathematical horizon .IP "\(bu" 4 \&\fB\-0.25\fR degrees .Sp Sun's upper limb touches a mathematical horizon .IP "\(bu" 4 \&\fB\-0.583\fR degrees .Sp Center of Sun's disk touches the horizon; atmospheric refraction accounted for .IP "\(bu" 4 \&\fB\-0.833\fR degrees .Sp Sun's supper limb touches the horizon; atmospheric refraction accounted for .IP "\(bu" 4 \&\fB\-6\fR degrees .Sp Civil twilight (one can no longer read outside without artificial illumination) .IP "\(bu" 4 \&\fB\-12\fR degrees .Sp Nautical twilight (navigation using a sea horizon no longer possible) .IP "\(bu" 4 \&\fB\-15\fR degrees .Sp Amateur astronomical twilight (the sky is dark enough for most astronomical observations) .IP "\(bu" 4 \&\fB\-18\fR degrees .Sp Astronomical twilight (the sky is completely dark) .SS "Notes on the Precise Algorithm" .IX Subsection "Notes on the Precise Algorithm" The original method only gives an approximate value of the Sun's rise/set times. The error rarely exceeds one or two minutes, but at high latitudes, when the Midnight Sun soon will start or just has ended, the errors may be much larger. If you want higher accuracy, you must then select the precise variant of the algorithm. This feature is new as of version 0.7. Here is what I (module creator) have tried to accomplish with this. .IP "a)" 4 .IX Item "a)" Compute sunrise or sunset as always, with one exception: to convert \s-1LHA\s0 from degrees to hours, divide by 15.04107 instead of 15.0 (this accounts for the difference between the solar day and the sidereal day. .IP "b)" 4 .IX Item "b)" Re-do the computation but compute the Sun's \s-1RA\s0 and Decl, and also \s-1GMST0,\s0 for the moment of sunrise or sunset last computed. .IP "c)" 4 .IX Item "c)" Iterate b) until the computed sunrise or sunset no longer changes significantly. Usually 2 iterations are enough, in rare cases 3 or 4 iterations may be needed. .PP However, I (second module maintainer) have checked with a few external sources, to obtain test data. And actually, using the value 15.0 gives results closer to what Stellarium and the \s-1NOAA\s0 solar calculator give. So I will use value 15.0, unless I find a bug in the precise algorithm as presently implemented. .SS "Notes on polar locations" .IX Subsection "Notes on polar locations" If the location is beyond either polar circle, and if the date is near either solstice, there can be midnight sun or polar night. In this case, there is neither sunrise nor sunset, and the module \f(CW\*(C`carp\*(C'\fRs that the sun never rises or never sets. Then, it returns the time at which the sun is at its highest or lowest point. .PP When computing twilights instead of sunrises / sunsets, the limit for polar locations extends a little beyond the polar circle. For example, for nautical twilights (12 degrees below the horizon), the limits where midnight sun might happen is 12 degrees southward of the Arctic Circle and 12 degrees northward of the Antarctic Circle, that is, about 54° latitude instead of 66°33′. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" This module requires: .IP "\(bu" 4 DateTime .IP "\(bu" 4 DateTime::Set .IP "\(bu" 4 DateTime::Span .IP "\(bu" 4 Params::Validate .IP "\(bu" 4 Set::Infinite .IP "\(bu" 4 \&\s-1POSIX\s0 .IP "\(bu" 4 Math::Trig .SH "BUGS AND CAVEATS" .IX Header "BUGS AND CAVEATS" Using a latitude of 90 degrees (North Pole or South Pole) gives curious results. I guess that it is linked with a ambiguous value resulting from a 0/0 computation. .PP Using a longitude of 177 degrees, or any longitude near the 180 meridian, may also give curious results, especially with the precise algorithm. .PP The precise algorithm should be thoroughly analysed, to understand why the value 15.04107 advised by Paul Schlyter does not give the expected results. .PP The precise algorithm is not tested with polar locations. At least, it is tested with a near-polar location, Fairbanks, at the time when the night is at its shortest, that is, in June. .SH "AUTHORS" .IX Header "AUTHORS" Original author: Ron Hill .PP Co-maintainer: Jean Forget .SH "SPECIAL THANKS" .IX Header "SPECIAL THANKS" .IP "Robert Creager [Astro\-Sunrise@LogicalChaos.org]" 4 .IX Item "Robert Creager [Astro-Sunrise@LogicalChaos.org]" for providing help with converting Paul's C code to perl. .IP "Flávio S. Glock [fglock@pucrs.br]" 4 .IX Item "Flávio S. Glock [fglock@pucrs.br]" for providing the the interface to the DateTime::Set module. .IP "Eric Jensen" 4 .IX Item "Eric Jensen" for positive and interesting advices about the new version of the module .SH "CREDITS" .IX Header "CREDITS" .IP "Paul Schlyter, Stockholm, Sweden" 4 .IX Item "Paul Schlyter, Stockholm, Sweden" for his excellent web page on the subject. .IP "Rich Bowen (rbowen@rbowen.com)" 4 .IX Item "Rich Bowen (rbowen@rbowen.com)" for suggestions. .IP "People at " 4 .IX Item "People at " for noticing an endless loop condition in Astro::Sunrise and for fixing it. .SH "COPYRIGHT and LICENSE" .IX Header "COPYRIGHT and LICENSE" .SS "Perl Module" .IX Subsection "Perl Module" This program is distributed under the same terms as Perl 5.16.3: \&\s-1GNU\s0 Public License version 1 or later and Perl Artistic License .PP You can find the text of the licenses in the \fI\s-1LICENSE\s0\fR file or at and . .PP Here is the summary of \s-1GPL:\s0 .PP This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \&\s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., . .SS "Original C program" .IX Subsection "Original C program" Here is the copyright information provided by Paul Schlyter for the original C program: .PP Written as \s-1DAYLEN.C, 1989\-08\-16\s0 .PP Modified to \s-1SUNRISET.C, 1992\-12\-01\s0 .PP (c) Paul Schlyter, 1989, 1992 .PP Released to the public domain by Paul Schlyter, December 1992 .PP Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \*(L"Software\*(R"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: .PP The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. .PP \&\s-1THE SOFTWARE IS PROVIDED \*(L"AS IS\*(R", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1). .PP DateTime Web page at .PP DateTime::Set .PP DateTime::SpanSet .PP Astro::Sunrise .PP DateTime::Event::Jewish::Sunrise .PP Astro::Coords .PP Astro::PAL .PP Paul Schlyter's homepage at .PP The \s-1NOAA\s0 solar calculator at