daylight 3.1.0 copy "daylight: ^3.1.0" to clipboard
daylight: ^3.1.0 copied to clipboard

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

example/example.dart

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

void main() {
  const london = const DaylightLocation(51.5072, 0.1276);
  final december = DateTime.utc(2024, 12, 1);

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

  // calculate for sunrise on civil twilight
  final civilSunrise = berlinSunCalculator.calculateEvent(
    december,
    Zenith.civil,
    EventType.sunrise,
  );

  print((
    "Civil sunrise:",
    civilSunrise?.formatStandard(),
  )); // utc: 07:03:16

  // calculate for sunrise and sunset on astronomical twilight
  final astronomicalEvents = berlinSunCalculator.calculateForDay(
    december,
    Zenith.astronomical,
  );
  print((
    "sunset",
    astronomicalEvents.sunset?.formatStandard(),
  )); // utc: 17:55:39
  print((
    "sunrise",
    astronomicalEvents.sunrise?.formatStandard(),
  )); // utc: 05:40:52
  print(astronomicalEvents.type); // DayType.sunriseAndSunset
}

extension on DateTime {
  String formatStandard() {
    return DateFormat("HH:mm:ss").format(this.toLocal());
  }
}
38
likes
160
pub points
83%
popularity

Publisher

verified publisherblue-fire.xyz

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

Repository (GitHub)
View/report issues

Topics

#daylight #time #location #timezone

Documentation

API reference

License

MIT (license)

Dependencies

equatable

More

Packages that depend on daylight