![]() |
![]()
| ![]() |
![]()
NAMEAstro::Sunrise - Perl extension for computing the sunrise/sunset on a given day VERSIONThis documentation refers to "Astro::Sunrise" version 0.99. SYNOPSIS# When did the sun rise on YAPC::Europe 2015? use Astro::Sunrise; my ($sunrise, $sunset) = sunrise( { year => 2015, month => 9, day => 2, # YAPC::EU starts on 2nd September 2015 lon => -3.6, lat => 37.17, # Granada is 37°10'N, 3°36'W tz => 1, isdst => 1 } ); # This is still summer, therefore DST # When does the sun rise today in Salt Lake City (home to YAPC::NA 2015)? use Astro::Sunrise; use DateTime; $sunrise_today = sun_rise( { lon => -111.88, lat => 40.75 } ); # 40°45'N, 111°53'W # And when does it set tomorrow at Salt Lake City? use Astro::Sunrise; use DateTime; $sunset_tomorrow = sun_set( { lat => 40.75, # 40°45'N, lon => -111.88, # 111°53'W alt => -0.833, # standard value for the sun altitude at sunset offset => 1 } ); # day offset up to tomorrow DESCRIPTIONThis module will return the sunrise and sunset for a given day. Months are numbered 1 to 12, in the usual way, not 0 to 11 as in C and in Perl's localtime. Eastern longitude is entered as a positive number Western longitude is entered as a negative number Northern latitude is entered as a positive number Southern latitude is entered as a negative number Please note that, when given as positional parameters, the longitude is specified before the latitude. The time zone is given as the numeric value of the offset from UTC. The "precise" parameter is set to either 0 or 1. If set to 0 no Iteration will occur. If set to 1 Iteration will occur, which will give a more precise result. Default is 0. There are a number of sun altitudes to chose 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 altitude (ALT) with, including symbolic constants for each.
USAGEsunrise($sunrise, $sunset) = sunrise( { year => $year, month => $month, day => $day, lon => $longitude, lat => $latitude, tz => $tz_offset, isdst => $is_dst, alt => $altitude, upper_limb => $upper_limb, precise => $precise, polar => $action, trace => $fh } ); ($sunrise, $sunset) = sunrise(YYYY,MM,DD,longitude,latitude,Time Zone,DST); ($sunrise, $sunset) = sunrise(YYYY,MM,DD,longitude,latitude,Time Zone,DST,ALT); ($sunrise, $sunset) = sunrise(YYYY,MM,DD,longitude,latitude,Time Zone,DST,ALT,precise); Returns the sunrise and sunset times, in HH:MM format. The first form uses a hash reference to pass arguments by name. The other forms are kept for backward compatibility. The arguments are:
For Example ($sunrise, $sunset) = sunrise( 2001, 3, 10, 17.384, 98.625, -5, 0 ); ($sunrise, $sunset) = sunrise( 2002, 10, 14, -105.181, 41.324, -7, 1, -18); ($sunrise, $sunset) = sunrise( 2002, 10, 14, -105.181, 41.324, -7, 1, -18, 1); sun_rise, sun_set$sun_rise = sun_rise( { lon => $longitude, lat => $latitude, alt => $altitude, upper_limb => $bool, offset => $day_offset, precise => $bool_precise, polar => $action } ); $sun_set = sun_set ( { lon => $longitude, lat => $latitude, alt => $altitude, upper_limb => $bool, offset => $day_offset, precise => $bool_precise, polar => $action } ); $sun_rise = sun_rise( $longitude, $latitude ); $sun_rise = sun_rise( $longitude, $latitude, $alt ); $sun_rise = sun_rise( $longitude, $latitude, $alt, $day_offset ); Returns the sun rise time (resp. the sun set time) for the given location and for today's date (as given by DateTime), plus or minus some offset in days. The first form use all parameters and transmit them by name. The second form uses today's date (from DateTime) and the default altitude. The third form adds specifying a custom altitude. The fourth form allows for specifying an integer day offset from today, either positive or negative. The parameters are the same as the parameters for "sunrise". There is an additional parameter, "offset", which allows using a date other than today: +1 for to-morrow, -7 for one week ago, etc. The arguments are:
For Example $sunrise = sun_rise( -105.181, 41.324 ); $sunrise = sun_rise( -105.181, 41.324, -15 ); $sunrise = sun_rise( -105.181, 41.324, -12, +3 ); $sunrise = sun_rise( -105.181, 41.324, undef, -12); Trigonometric functions using degreesSince the module use trigonometry with degrees, the corresponding functions are available to the module user, free of charge. Just mention the tag ":trig" in the "use" statement. These functions are:
EXPORTSBy default, the functions "sunrise", "sun_rise" and "sun_set" are exported. The constants "DEFAULT", "CIVIL", "NAUTICAL", "AMATEUR" and "ASTRONOMICAL" are exported on request with the tag ":constants". The functions "sind", "cosd", "tand", "asind", "acosd", "atand", "atan2d" and "equal" exported on request with the tag ":trig". DEPENDENCIESThis module requires only core modules: POSIX, Math::Trig and Carp. If you use the "sun_rise" and "sun_set" functions, you will need also DateTime. BUGS AND ISSUESBefore reporting a bug, please read the text doc/astronomical-notes.pod because the strange behavior you observed may be a correct one, or it may be a corner case already known and already mentioned in the text. Nevertheless, patches and (justified) bug reports are welcome. See <https://github.com/jforget/Astro-Sunrise/issues> and <https://github.com/jforget/Astro-Sunrise/pulls>. Precise AlgorithmThe explanations for the precise algorithm give a pretty good reason for using an angular speed of 15.04107 instead of 15. Yet, computations with 15.04107 do not give results conforming to what the NOAA website and Stellarium give, while computations with 15 give conforming results. The implementation of the precise algorithm should be analysed and checked to find the reason why 15.04107 does not give the proper results. KwaliteeThe CPANTS tools do not recognize the LICENSE POD paragraph. But any human reader will admit that this LICENSE paragraph exists and is valid. Haiku-OS CPAN TesterThe built-in test t/06datetime.t fails on Haiku-OS because there is no way to extract the timezone name from the system parameters. This failure does not affect the core functions of Astro::Sunrise. Also reported from a user working on a partially configured FreeBSD machine, see <https://github.com/jforget/Astro-Sunrise/issues/16>. Hopefully, this will be fixed in the current version. AUTHORRon Hill rkhill@firstlight.net Co-maintainer: Jean Forget (JFORGET at cpan dot org) SPECIAL THANKSRobert Creager [Astro-Sunrise@LogicalChaos.org] for providing help with converting Paul's C code to Perl, for providing code for sun_rise, sun_set subs. Also adding options for different altitudes. Joshua Hoblitt [jhoblitt@ifa.hawaii.edu] for providing the patch to convert to DateTime. Chris Phillips for providing patch for conversion to local time. Brian D Foy for providing patch for constants :) Gabor Szabo for pointing POD mistakes. People at <https://geocoder.opencagedata.com/> for noticing an endless loop condition and for fixing it. CREDITS
Lightly verified against <http://aa.usno.navy.mil/data/docs/RS_OneYear.html> In addition, checked to be compatible with a C implementation of Paul Schlyter's algorithm. COPYRIGHT and LICENSEPerl ModuleCopyright (C) 1999-2003, 2013, 2015, 2017, 2019, 2021 Ron Hill and Jean Forget, all rights reserved. This program is distributed under the same terms as Perl 5.16.3: GNU Public License version 1 or later and Perl Artistic License You can find the text of the licenses in the LICENSE file or at <https://dev.perl.org/licenses/artistic.html> and <https://www.gnu.org/licenses/gpl-1.0.html>. Here is the summary of GPL: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., <https://www.fsf.org/>. Original C programHere is the copyright information provided by Paul Schlyter: Written as DAYLEN.C, 1989-08-16 Modified to SUNRISET.C, 1992-12-01 (c) Paul Schlyter, 1989, 1992 Released to the public domain by Paul Schlyter, December 1992 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", 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. SEE ALSOperl(1). DateTime::Event::Sunrise DateTime::Event::Jewish::Sunrise The text doc/astronomical-notes.pod (or its original French version doc/notes-astronomiques) in this distribution. <https://stjarnhimlen.se/comp/riset.html>
|