App-TimeClock

 view release on metacpan or  search on metacpan

lib/App/TimeClock/Daily/ConsolePrinter.pm  view on Meta::CPAN

package App::TimeClock::Daily::ConsolePrinter;

use strict;
use warnings;

our @ISA = qw(App::TimeClock::Daily::PrinterInterface);

use POSIX qw(strftime);

use utf8;
binmode STDOUT, ':utf8';

our $hrline =  '+' . ('-' x 62) . '+' . ('-' x 7) . '+';

=head1 NAME

App::TimeClock::Daily::ConsolePrinter

=head1 DESCRIPTION

Implements the L<App::TimeClock::Daily::PrinterInterface>. Will print a simple ASCII
format. Suitable for using in a console/terminal.

=head1 METHODS

=over

=cut

=item print_header()

Prints a header including todays date. The header is indented to be
centered above the tables printed by L</print_day()>. Example:

                 =====================================
                 Daily Report Wed Mar 14 13:39:06 2012
                 =====================================

=cut
sub print_header {
    my $self = shift;
    my $ident = ' ' x 17;
    $self->_print("\n");
    $self->_print("${ident}=====================================\n");
    $self->_print("${ident}Daily Report " . localtime() . "\n");
    $self->_print("${ident}=====================================\n\n");
};

=item print_day()

Prints all activities for a day including a total. Is printed in a ACSII
table. Example:

 * Mon 2012/03/12 (08:21:16 - 16:05:31) *
 +--------------------------------------------------------------+-------+
 | Total Daily Hours                                            |  7.73 |
 +--------------------------------------------------------------+-------+
 | Lunch                                                        |  0.57 |
 +--------------------------------------------------------------+-------+
 | MyProject:Estimation                                         |  2.90 |
 +--------------------------------------------------------------+-------+
 | AnotherProject:BugFixing                                     |  4.26 |
 +--------------------------------------------------------------+-------+

=cut
sub print_day {
    my ($self, $date, $start, $end, $work, %projects) = (@_);
    my ($year, $mon, $mday) = split(/\//, $date);
    my $wday = substr(strftime("%a", 0, 0, 0, $mday, $mon-1, $year-1900),0,3);

    $self->_print(sprintf("* %3s %s (%s - %s) *\n", $wday, $date, $start, $end));



( run in 2.078 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )