astrocalc 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 3

AstroCalc #

This library is a Dart port of the awesome Vladimir Agafonkin (@mourner)'s JavaScript library for calculating sun and moon positions and phases for a given location and time.

Calculations for other solar system bodies are also in the works.

Usage #

AstroCalc is available on Pub.

See the examples folder for usage examples.

Reference #

BaseCalc #

// Latitude and longitude in degrees
BaseCalc baseCalcChild = BaseCalcChild({ DateTime date, num longitude, num latitude })

All celestial body classes inherit from the abstract class BaseCalc. On instantiation, they all calculate and expose the following properties of the body for the provided location and time (each is a Map):

eclipticCoordsEarth-based ecliptic coordinates: latitude (eclipticCoords['lat']) and longitude (eclipticCoords['lng'])
equatorialCoordsEquatorial coordinates: right ascension (equatorialCoords['ra'] and declination equatorialCoords['dec'])
positionEarth-based horizontal coordinates: azimuth (position['azimuth']) and altitude (position['altitude'])
timesTimes of astronomical interest (body-specific)

The coordinate systems are returned in radians. For more information on each, see the following links:

SunCalc #

SunCalc sunCalc = new SunCalc({ DateTime date, num longitude, num latitude })

In addition to the coordinate systems, SunCalc calculates the following times (accessible as properties of the Map sunCalc.times)

nightEndnight ends (morning astronomical dawn starts)
nauticalDawnnautical dawn (morning nautical dawn starts)
dawndawn (morning nautical dawn ends, morning civil dawn starts)
sunrisesunrise (top edge of the sun appears on the horizon)
sunriseEndsunrise ends (bottom edge of the sun touches the horizon)
goldenHourEndmorning golden hour (soft light, best time for photography) ends
solarNoonsolar noon (sun is in the highest position)
goldenHourevening golden hour starts
sunsetStartsunset starts (bottom edge of the sun touches the horizon)
sunsetsunset (sun disappears below the horizon, evening civil twilight starts)
duskdusk (evening nautical twilight starts)
nauticalDusknautical dusk (evening astronomical twilight starts)
nightnight starts (dark enough for astronomical observations)
nadirnadir (darkest moment of the night, sun is in the lowest position)

Changelog #

All notable changes to this project will be documented in this file.

28/09/2017 (0.0.1) #

Added #

  • Base, extendable calc class with calculations for:

    • Ecliptic coordinates (latitude and longitude)
    • Equatorial coordinates (right ascension and declination)
    • Horizonatal coordinates (azimuth and altitude)
  • Times calculations for the Sun

    • nightEnd
    • nauticalDawn
    • dawn
    • sunrise
    • sunriseEnd
    • goldenHourEnd
    • solarNoon
    • goldenHour
    • sunsetStart
    • sunset
    • dusk
    • nauticalDusk
    • night
    • nadir


import 'package:astrocalc/astrocalc.dart';

main() {
  SunCalc sunCalc = new SunCalc(
    date: new,
    longitude: 3.3839178,
    latitude: 6.5069113

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  astrocalc: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:astrocalc/astrocalc.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0