#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use App::datecalc;
use Term::ReadLine;

our $VERSION = '0.01'; # VERSION
our $DATE = '2014-05-20'; # DATE

my $calc = App::datecalc->new;

my $term = Term::ReadLine->new('datecalc');
my $prompt = "> ";
my $OUT = $term->OUT || \*STDOUT;

while ( defined ($_ = $term->readline($prompt)) ) {
    my $res;
    eval { $res = $calc->eval($_) };
    if ($@) {
        warn "Error: $@\n";
    } else {
        print $OUT $res, "\n";
    }
    $term->addhistory($_) if /\S/;
}

# ABSTRACT: Date calculations
# PODNAME: datecalc

__END__

=pod

=encoding UTF-8

=head1 NAME

datecalc - Date calculations

=head1 VERSION

This document describes version 0.01 of datecalc (from Perl distribution App-datecalc), released on 2014-05-20.

=head1 SYNOPSIS

 % datecalc

 > today
 2014-05-13

 > tomorrow
 2014-05-14

 > today + 2 days
 2014-05-15

 > 2014-05-13 - 2014-02-14
 P2M3W6D

 > 2 months 3 weeks 6 days
 P2M3W6D

 > P10D
 P1W3D

 > 2014-05-13 + P2D
 2014-05-15

 > 2 * 2 days 10 hours
 P4DT20H

 > P10D / 2
 P5D

 > 6d + 8d + 13 min
 P2WT13M

=head1 DESCRIPTION

This is a command-line utility to perform date calculations.

For now, for more details, see L<App::datecalc>.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-datecalc>.

=head1 SOURCE

Source repository is at L<https://github.com/sharyanto/perl-App-datecalc>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-datecalc>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
