Open source · MIT licence
uzytak_sun_moon
Sunrise, sunset, moonrise, moonset, Moon phase and illumination for any place on Earth. Pure Dart, no dependencies, works in Flutter and in command-line Dart.
Адкрыты код: усход і захад Сонца і Месяца, фаза Месяца.Otwarty kod: wschód i zachód Słońca i Księżyca, faza Księżyca.
What it is
Our own implementation of public astronomical formulas: the NOAA solar equations and the Meeus low-precision lunar theory with topocentric parallax. It was written for the Belarusian tear-off calendar and is now open, so that anyone can use it and check it.
- sunTimes: sunrise, sunset and solar noon, polar day and polar night.
- moonTimes: moonrise and moonset, days without a rise or a set, Moon above or below the horizon all day.
- moonIllumination: illuminated fraction, phase and bright-limb angle.
Accuracy against Swiss Ephemeris
Compared with Swiss Ephemeris 2.10.03 on 12 places (Warsaw, Minsk, New York, Sydney, Quito, Singapore, Buenos Aires, Reykjavik, Fairbanks, Tromsø, Murmansk, Longyearbyen) and 24 dates between January 2026 and August 2028: 288 place-days. Rise and set mean the upper limb at the horizon with standard refraction.
| Quantity | Compared values | Mean error | 95th percentile | Maximum error |
|---|---|---|---|---|
| Sunrise and sunset, latitude up to 65° | 432 | 0.08 min | 0.21 min | 0.62 min |
| Sunrise and sunset, latitude above 65° | 78 | 0.19 min | 0.45 min | 1.27 min |
| Moonrise and moonset, latitude up to 65° | 400 | 0.07 min | 0.16 min | 0.57 min |
| Moonrise and moonset, latitude above 65° | 73 | 0.19 min | 0.61 min | 0.81 min |
| Moon illuminated fraction | 288 | 0.009 pp | 0.018 pp | 0.019 pp |
Two moon events within 3 minutes of the edge of the compared 24-hour window are left out. In every other case the package and the reference agree on whether an event exists at all. The numbers are measured by the test tool in the package; they describe these places and years, not a guarantee for every place and date. For calendars and planners, not for navigation.
Install and use
dart pub add uzytak_sun_moon
import 'package:uzytak_sun_moon/uzytak_sun_moon.dart';
void main() {
const lat = 52.2297, lng = 21.0122; // Warsaw
// Sun: any instant near the middle of the wanted day
final sun = sunTimes(DateTime.utc(2026, 11, 15, 12), lat, lng);
if (!sun.polar) print('${sun.rise} ${sun.set}'); // UTC instants
// Moon: the 24 hours that start at the given instant
final moon = moonTimes(DateTime.utc(2026, 11, 15), lat, lng);
print('${moon.rise} ${moon.set}'); // either can be null
final ill = moonIllumination(DateTime.utc(2026, 11, 15, 12));
print('${(ill.fraction * 100).toStringAsFixed(1)} % lit');
}
Good to know
- Time zones. All results are UTC instants. Convert them to a local zone yourself.
- Polar day and night.
SunTimes.polaris true and rise and set are null. - The Moon can have no rise or no set on a day. It rises about 50 minutes later every day. Then the value is null, which is correct and not an error.
- Sea level. No correction for mountains or for the height of the observer.
Licence
MIT. Free for any use, also commercial. Keep the notice below in your copy.
MIT License
Copyright (c) 2026 UZYTAK
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
AUTHORS OR COPYRIGHT HOLDERS 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.