version 1.5, 2020/08/04 02:28:24 |
version 1.6, 2020/08/20 03:15:23 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $AFresh1: report_time,v 1.4 2020/08/04 01:24:44 afresh1 Exp $ |
# $AFresh1: report_time,v 1.5 2020/08/04 01:28:24 afresh1 Exp $ |
use v5.16; |
use v5.16; |
use warnings; |
use warnings; |
|
|
my $dir = "$ENV{HOME}/.time"; |
my $dir = "$ENV{HOME}/rt_invoicing/time"; |
|
|
my %conversions = ( |
my %conversions = ( |
m => "Misc", |
m => "Misc", |
|
|
map { "$dir/$_" } sort grep { /^\d{4}-\d{2}-\d{2}$/ } readdir $dh; |
map { "$dir/$_" } sort grep { /^\d{4}-\d{2}-\d{2}$/ } readdir $dh; |
}; |
}; |
|
|
my %entries; |
my @entries; |
foreach my $file (@files) { |
foreach my $file (@files) { |
my $key = 'm'; |
|
|
|
open my $fh, '<', $file or die "Unable to open $file: $!"; |
open my $fh, '<', $file or die "Unable to open $file: $!"; |
while (readline $fh) { |
while (readline $fh) { |
my ($dt, $type, $description) |
my ($dt, $type, $description) |
|
|
my %entry = ( dt => $dt, type => $type ); |
my %entry = ( dt => $dt, type => $type ); |
$entry{description} = $description if $description; |
$entry{description} = $description if $description; |
|
|
$key = descr_to_key($description) |
push @entries, \%entry; |
if $type eq 'sta' and $description; |
|
|
|
push @{ $entries{$key} }, \%entry; |
|
} |
} |
close $fh; |
close $fh; |
} |
} |
|
|
my %total; |
my %total; |
foreach my $key (sort keys %entries) { |
{ |
my $start; |
my $start; |
foreach my $entry (@{ $entries{$key} }) { |
my $key = 'm'; |
|
foreach my $entry (@entries) { |
|
|
# Sat Jul 11 11:56:06 PDT 2020 |
# Sat Jul 11 11:56:06 PDT 2020 |
$entry->{datetime} = Time::Piece->new->strptime( |
$entry->{datetime} = Time::Piece->new->strptime( |
$entry->{dt}, "%a %b %e %H:%M:%S %Z %Y"); |
$entry->{dt}, "%a %b %e %H:%M:%S %Z %Y"); |
|
|
$total{ $entry->{datetime}->date }{$key} |
if ($start) { |
+= $entry->{datetime} - $start->{datetime} |
$key = descr_to_key($start->{description}) |
if $start; |
if $start->{description}; |
|
$total{ $entry->{datetime}->date }{$key} |
|
+= $entry->{datetime} - $start->{datetime}; |
|
} |
|
|
$start = $entry->{type} eq 'sta' ? $entry : ''; |
$start = $entry->{type} eq 'sta' ? $entry : ''; |
} |
} |
|
|
# If we have a timer running, pretend it stops now. |
# If we have a timer running, pretend it stops now. |
if ($start) { |
if ($start) { |
|
$key = descr_to_key($start->{description}) |
|
if $start->{description}; |
my $now = localtime; |
my $now = localtime; |
$total{ $now->date }{$key} += $now - $start->{datetime} |
$total{ $now->date }{$key} += $now - $start->{datetime} |
} |
} |