daylight 2.0.0 icon indicating copy to clipboard operation
daylight: ^2.0.0 copied to clipboard

Get the sunset and sunrise times for a geolocation without having to access any api.

example/example.dart

import 'package:intl/intl.dart';
import 'package:daylight/daylight.dart';

void main() {
  const berlin = const DaylightLocation(52.518611, 13.408056);
  final october = DateTime(2020, 10, 15);

  // Create berlin calculator
  const berlinSunCalculator = const DaylightCalculator(berlin);

  // calculate for sunrise on civil twilight
  final civilSunrise = berlinSunCalculator.calculateEvent(
    october,
    Zenith.civil,
    EventType.sunrise,
  );
  print(DateFormat("HH:mm:ss").format(civilSunrise)); // utc: 04:58:18

  // calculate for sunrise and sunset on astronomical twilight
  final astronomicalEvents = berlinSunCalculator.calculateForDay(
    october,
    Zenith.astronomical,
  );
  print(
    DateFormat("HH:mm:ss").format(astronomicalEvents.sunset),
  ); // utc: 18:03:55
  print(
    DateFormat("HH:mm:ss").format(astronomicalEvents.sunrise),
  ); // utc: 03:39:09
  print(astronomicalEvents.type); // DayType.sunriseAndSunset
}
24
likes
130
pub points
81%
popularity

Publisher

verified publisher iconblue-fire.xyz

Get the sunset and sunrise times for a geolocation without having to access any api.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

angles, intl

More

Packages that depend on daylight