App-JobLog

 view release on metacpan or  search on metacpan

lib/App/JobLog/Log/Day.pm  view on Meta::CPAN

sub synopses { $_[0]->{synopses} }


sub is_empty {
    my ($self) = @_;
    return !( @{ $self->events } || @{ $self->vacation } );
}

sub show_date { !$_[0]->no_date }

sub no_date { $_[0]->{no_date} }


sub times {
    my ( $self, $times ) = @_;
    return if $self->concerns_notes;

    for my $e ( @{ $self->events }, @{ $self->vacation } ) {
        my @tags = @{ $e->tags };
        my $d    = $e->duration;
        $times->{tags}{$_} += $d for @tags;
        $times->{untagged} += $d unless @tags;
        $times->{total} += $d;
        $times->{vacation} += $d if $e->isa('App::JobLog::Vacation::Period');
    }
    $times->{expected} += WORK_SECONDS
      if is_workday $self->start;
}


sub display {
    my ( $self, $format, $columns, $screen_width, $show_year ) = @_;
    return if $self->is_empty;

    # cache some bits from the $columns hash
    my ( $show_times, $show_durations, $show_tags, $show_descriptions ) =
      @{ $columns->{formats} }{qw(time duration tags description)};
    my $show_date = $columns->{date};
    my ( $tag_width, $description_width ) =
      @{ $columns->{widths} }{qw(tags description)};

    # date
    if ($show_date) {
        my $f = $show_year ? '%A, %e %B, %Y' : '%A, %e %B';
        print $self->start->strftime($f), "\n";
    }

    # activities
    for my $s ( @{ $self->synopses } ) {
        my @lines;
        push @lines, [ $s->time_fmt ] if $show_times;
        push @lines, [ duration( $s->duration ) ] if $show_durations;
        push @lines, wrap( $s->tag_string, $tag_width ) if $show_tags;
        push @lines, $screen_width == -1
          ? [ $s->description ]
          : wrap( $s->description, $description_width )
          if $show_descriptions;
        my $count = _pad_lines( \@lines );

        for my $i ( 0 .. $count ) {
            say sprintf $format, _gather( \@lines, $i );
        }
    }
    print "\n"
      if $show_times
          || $show_durations
          || $show_tags
          || $show_descriptions
          || $show_date;
}

# add blank lines to short columns
# returns the number of lines to print
sub _pad_lines {
    my ($lines) = @_;
    my $max = 0;
    for my $column (@$lines) {
        $max = @$column if @$column > $max;
    }
    for my $column (@$lines) {
        push @$column, '' while @$column < $max;
    }
    return $max - 1;
}

# collect the pieces of columns corresponding to a particular line to print
sub _gather {
    my ( $lines, $i ) = @_;
    my @line;
    for my $column (@$lines) {
        push @line, $column->[$i];
    }
    return @line;
}


sub pseudo_event {
    my ($self) = @_;
    unless ( $self->{pseudo_event} ) {
        my $e =
          App::JobLog::Log::Event->new(
            App::JobLog::Log::Line->new( time => $self->start ) );
        $e->end = $self->end;
        $self->{pseudo_event} = $e;
    }
    return $self->{pseudo_event};
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

App::JobLog::Log::Day - collects events and vacation in a complete day

=head1 VERSION



( run in 0.688 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )