use vars qw/ $withDateTime /; if( $withDateTime ){ use if $withDateTime,qw/ DateTime::Span /; use if $withDateTime,qw/ DateTime::Format::Strptime /; #~ use DateTime::Span; #~ use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new( #~ 29.10.2008 13:00:00 #~ %d.%m.%Y %T pattern => '%d.%m.%Y %T', ); my $span_a = DateTime::Span->from_datetimes( start => $strp->parse_datetime($start_a_str), end => $strp->parse_datetime($end_a_str), ); my $span_b = DateTime::Span->from_datetimes( start => $strp->parse_datetime($start_b_str), end => $strp->parse_datetime($end_b_str), ); my $set = $span_a->intersection( $span_b ); my $dur = $set->duration; my $thours = 0; $thours += $dur ->years *365*24; $thours += $dur ->months *30*24; $thours += $dur ->weeks *7*24; $thours += $dur ->days *24; $thours += $dur ->hours ; $thours += $dur ->minutes / 60 ; $thours += $dur ->seconds / 60 / 60 ; # irrelevant $thours = sprintf '%.f', $thours; # round $hash{$wds} += $thours if $thours; next STRING; }