This queue is for tickets about the DateTime-BusinessHours CPAN distribution.

Report information
The Basics

Nobody in particular
oriol.soriano [...]

(no value)
Broken in:
(no value)
Fixed in:
(no value)

Subject: DateTime::BusinessHours - negative get_hours values
Date: Tue, 14 May 2013 16:34:10 +0000
To: "" <>, "" <>
From: Oriol Soriano <>




First  and foremost, I honestly appreciate the effort invested in DateTime::BusinessHours;  I did find out that, seeing yourself in the need of a "business hours/days" calculator, you requested comaint of this module. So, to begin with, thanks for your work!


Now, apparently, and unless I am misunderstanding how the module is supposed to work,  I have found a bug.

Given a time interval the totally of which falls into a ‘non-working’ period of time, the get_hours() method returns, at least in the following cases , a negative value.

It is my understanding that the returned value should be 0; since no business time at all has gone by during that period of time. Instead, the returned ‘business time’ value is exactly the amount of time from the end of the specified interval to the beginning of the next ‘working’ period of time.


This happened on…

Module version: 2.02

Perl version:  v5.14.2

OS:  Debian Lenny


The following tests fail:


#!/usr/bin/env perl

use Test::More tests => 2;

use strict;

use warnings;


use DateTime::BusinessHours;

use DateTime;


my $dt1 = DateTime->new(

    year   => 2013,

    month  => 5,

    day    => 14,

    hour   => 3,

    minute => 9,


my $dt2 = DateTime->new(

    year   => 2013,

    month  => 5,

    day    => 14,

    hour   => 8,

    minute => 0,



my $btime = DateTime::BusinessHours->new(

    datetime1  => $dt1,

    datetime2  => $dt2,

    worktiming => [9, 18],



is( $btime->gethours(),   0, 'btime is 0' );

ok( $btime->gethours() >= 0, 'btime not negative' );


(the returned value is ‘-1’)


If you would preffer having this posted at RT or at any other place, just let me know.




Oriol Soriano


PS: Seeing a link to your available at your CPAN profile page, couldn’t resist to give it a look. Nice music taste ;)


This should now be fixed in version 2.03: PS: Thanks for the music compliment :)

This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with to