#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std qw{getopts};
use DateTime;
use DateTime::Event::Sunrise;
use Geo::Local::Server;

my $opt     = {};
getopts("f:", $opt);

my $file    = $opt->{"f"};
my $now     = DateTime->now;
my $gls     = Geo::Local::Server->new(configfile=>$file);
my $lat     = $gls->lat;
my $lon     = $gls->lon;
my $alt     = -0.833;
my $sunset  = DateTime::Event::Sunrise
                ->sunset(longitude=>$lon, latitude=>$lat, altitude=>$alt, precise=>1)
                  ->next($now)
                    ->set_time_zone("local");

printf "%02d:%02d\n", $sunset->hour, $sunset->minute;

__END__

=head1 NAME

sunset_time - Prints the time of the next sunset

=head1 SYNOPSIS

  sunset_time
  sunset_time [-f FILE]
  echo "task" | at `sunset_time`

=head1 OPTIONS

=head2 -f FILE - default /etc/local.coordinates

Specify alternate configuration file

=head1 DESCRIPTION

Uses the system coordinates as configured from the perl package Geo::Local::Server and with the perl package DateTime::Event::Sunrise to calculate the next sunset.

=cut

