Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All! any idea how can i create a work hour report of my total work hours per day? (ex, 08:30 - 19:15 = 10.75Hrs)

Replies are listed 'Best First'.
Re: Monthly hours report
by Your Mother (Archbishop) on Jun 21, 2009 at 21:39 UTC

    I don't know how tolerant of timezone and DST issues this is so if you use it, manually check the math or ask the DateTime mailing list for advice (I love the kit but I'm not a power user).

    use strict; use warnings; use DateTime; my $in = DateTime->new( year => 2009, month => 06, day => 22, hour => 8, minute => 30, second => 0, ); my $out = DateTime->new( year => 2009, month => 06, day => 22, hour => 17, minute => 15, second => 0, ); my $duration = $out - $in; printf("%.2f hour(s)\n", $duration->days * 24 + $duration->hours + $duration->minutes / 60 ); __END__ 8.75 hour(s)
Re: Monthly hours report
by moritz (Cardinal) on Jun 21, 2009 at 20:07 UTC
    By using an appropriate module from CPAN.

    (A very general question is bound to receive a very general answer).

Re: Monthly hours report
by Anonymous Monk on Jun 22, 2009 at 00:02 UTC
    tracker
    tracker start something tracker start something detail tracker start somethingelse tracker current tracker stop tracker worked something
    App::TimeTracker Requires perl 5.10
      Here's a patch to run App::TimeTracker on perl 5.8.x
      diff -ruN App-TimeTracker-0.21-orig/bin/tracker App-TimeTracker-0.21-n +ew/bin/tracker --- App-TimeTracker-0.21-orig/bin/tracker 2009-02-17 10:52:29.00000 +0000 -0800 +++ App-TimeTracker-0.21-new/bin/tracker 2009-06-21 18:53:11.984375 +000 -0700 @@ -1,5 +1,5 @@ #!/usr/bin/perl -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker; diff -ruN App-TimeTracker-0.21-orig/Build.PL App-TimeTracker-0.21-new/ +Build.PL --- App-TimeTracker-0.21-orig/Build.PL 2009-02-17 10:52:29.00000000 +0 -0800 +++ App-TimeTracker-0.21-new/Build.PL 2009-06-21 19:01:48.109375000 + -0700 @@ -8,6 +8,7 @@ dist_author => 'Thomas Klausner <domm@cpan.org>', dist_version_from => 'lib/App/TimeTracker.pm', requires => { + 'any::feature' => 0.01, 'DateTime' => 0.41, 'DateTime::Format::Strptime'=> 1.0702, 'File::HomeDir' => 0.67, diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/conver +t_to_0_20.pm App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/con +vert_to_0_20.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/convert_to_0 +_20.pm 2009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/convert_to_0_ +20.pm 2009-06-21 18:53:11.984375000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::convert_to_0_20; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/curren +t.pm App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/current.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/current.pm + 2009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/current.pm + 2009-06-21 18:53:12.000000000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::current; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/report +.pm App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/report.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/report.pm + 2009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/report.pm +2009-06-21 18:53:12.000000000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::report; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/start. +pm App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/start.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/start.pm +2009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/start.pm 2 +009-06-21 18:53:12.000000000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::start; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/stop.p +m App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/stop.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/stop.pm 2 +009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/stop.pm 20 +09-06-21 18:53:12.015625000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::stop; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/sync.p +m App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/sync.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/sync.pm 2 +009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/sync.pm 20 +09-06-21 18:53:12.015625000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::sync; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/worked +.pm App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/worked.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command/worked.pm + 2009-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command/worked.pm +2009-06-21 18:53:12.031250000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command::worked; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::TimeTracker -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command.pm App +-TimeTracker-0.21-new/lib/App/TimeTracker/Command.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Command.pm 2009-0 +2-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Command.pm 2009-06 +-21 18:53:12.031250000 -0700 @@ -1,5 +1,5 @@ package App::TimeTracker::Command; -use 5.010; +use any::feature 'say'; use strict; use warnings; use App::Cmd::Setup -command; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Exceptions.pm +App-TimeTracker-0.21-new/lib/App/TimeTracker/Exceptions.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Exceptions.pm 200 +9-02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Exceptions.pm 2009 +-06-21 18:53:12.031250000 -0700 @@ -1,6 +1,6 @@ package App::TimeTracker::Exceptions; -use 5.010; +use any::feature 'say'; use warnings; use strict; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Projects.pm Ap +p-TimeTracker-0.21-new/lib/App/TimeTracker/Projects.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Projects.pm 2009- +02-17 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Projects.pm 2009-0 +6-21 18:53:12.046875000 -0700 @@ -1,6 +1,6 @@ package App::TimeTracker::Projects; -use 5.010; +use any::feature 'say'; use warnings; use strict; @@ -95,7 +95,7 @@ || ATTX::File->throw("Cannot write to $path: $!"); foreach my $project ( sort keys %{ $self->list } ) { - say $fh $project; + say $fh, $project; } close $fh; diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker/Task.pm App-Ti +meTracker-0.21-new/lib/App/TimeTracker/Task.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker/Task.pm 2009-02-1 +7 10:52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker/Task.pm 2009-06-21 + 18:53:12.046875000 -0700 @@ -1,6 +1,6 @@ package App::TimeTracker::Task; -use 5.010; +use any::feature 'say'; use warnings; use strict; @@ -154,10 +154,10 @@ open( my $fh, ">", $file ) || ATTX::File->throw("Cannot write to $file: $!"); foreach my $fld (qw(project tags)) { - say $fh "$fld: " . ( $self->$fld || '' ); + say $fh, "$fld: " . ( $self->$fld || '' ); } foreach my $fld (qw(start stop)) { - say $fh "$fld: " . ( $self->$fld ? $self->$fld->epoch : '' ); + say $fh, "$fld: " . ( $self->$fld ? $self->$fld->epoch : '' ) +; } close $fh; @@ -179,7 +179,7 @@ open( my $fh, ">", $current ) || ATTX::File->throw("Cannot write file $current: $!"); - say $fh $self->_calc_path; + say $fh, $self->_calc_path; close $fh; return $self; } diff -ruN App-TimeTracker-0.21-orig/lib/App/TimeTracker.pm App-TimeTra +cker-0.21-new/lib/App/TimeTracker.pm --- App-TimeTracker-0.21-orig/lib/App/TimeTracker.pm 2009-02-17 10: +52:29.000000000 -0800 +++ App-TimeTracker-0.21-new/lib/App/TimeTracker.pm 2009-06-21 18:5 +3:12.062500000 -0700 @@ -1,6 +1,6 @@ package App::TimeTracker; -use 5.010; +use any::feature 'say'; use warnings; use strict; use version; our $VERSION = version->new('0.21'); @@ -116,32 +116,32 @@ my $date; eval { - if ( $datetime =~ /^(?<hour>\d\d):?(?<minute>\d\d)$/ ) + if ( $datetime =~ /^(\d\d):?(\d\d)$/ ) { $date = DateTime->new( year => $n->year, month => $n->month, day => $n->day, - hour => $+{hour}, - minute => $+{minute}, + hour => $1, + minute => $2, second => 0, time_zone => 'local', ); } elsif ( $datetime =~ / - (?<month>\d\d)\.?(?<day>\d\d) + (\d\d)\.?(\d\d) [-_] - (?<hour>\d\d):?(?<minute>\d\d) + (\d\d):?(\d\d) /x ) { $date = DateTime->new( year => $n->year, - month => $+{month}, - day => $+{day}, - hour => $+{hour}, - minute => $+{minute}, + month => $1, + day => $2, + hour => $3, + minute => $4, second => 0, time_zone => 'local', );
      apply with
      cd App-TimeTracker-0.21 patch -p1 -N < ../App-TimeTracker-0.21.patch