#!/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 $des     = DateTime::Event::Sunrise->new(latitude=>$lat, longitude=>$lon);
my $sunset  = $des->sunset_datetime($now)->set_time_zone("local");  #per the documentation this is the next sunset

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

