[Rt-commit] r3431 - in Business-Hours/trunk: . lib/Business t
glasser at bestpractical.com
glasser at bestpractical.com
Fri Jul 8 10:47:12 EDT 2005
Author: glasser
Date: Fri Jul 8 10:47:12 2005
New Revision: 3431
Added:
Business-Hours/trunk/t/
Business-Hours/trunk/t/1-business-hours.t
Business-Hours/trunk/t/99-pod-coverage.t
Business-Hours/trunk/t/99-pod.t
Modified:
Business-Hours/trunk/MANIFEST
Business-Hours/trunk/Makefile.PL
Business-Hours/trunk/lib/Business/Hours.pm
Log:
Business::Hours cleanups:
* Unembed tests
* POD cleanup (and add pod tests)
* no longer an exporter that exports nothing
* http://rt.cpan.org/Ticket/Display.html?id=13374:
in certain time zones (try Guam, for example), the epoch
is a business hour, which led to some tests being run with
start hours of 0, which caught a few places in the code that
were checking $hours->first when they should have been checking
defined $hours->first (or actually $hours->empty)
Version has not been bumped, but I recommend bumping and releasing.
Modified: Business-Hours/trunk/MANIFEST
==============================================================================
--- Business-Hours/trunk/MANIFEST (original)
+++ Business-Hours/trunk/MANIFEST Fri Jul 8 10:47:12 2005
@@ -1,8 +1,11 @@
-MANIFEST
-LICENSE
-README
-Todo
Changes
lib/Business/Hours.pm
+LICENSE
Makefile.PL
+MANIFEST
META.yml
+README
+t/1-business-hours.t
+t/99-pod-coverage.t
+t/99-pod.t
+Todo
Modified: Business-Hours/trunk/Makefile.PL
==============================================================================
--- Business-Hours/trunk/Makefile.PL (original)
+++ Business-Hours/trunk/Makefile.PL Fri Jul 8 10:47:12 2005
@@ -5,35 +5,6 @@
NAME => 'Business::Hours',
VERSION_FROM => 'lib/Business/Hours.pm', # finds $VERSION
AUTHOR => 'Jesse Vincent (jesse at cpan.org)',
- PREREQ_PM => { Test::Inline => 0,
- Set::IntSpan => 0},
+ PREREQ_PM => { Set::IntSpan => 0},
ABSTRACT => '',
);
-
- {
- package MY;
- sub top_targets {
- my($self) = @_;
- my $out = "POD2TEST_EXE = pod2test\n";
-
- $out .= $self->SUPER::top_targets(@_);
- $out =~ s/^(pure_all\b.*)/$1 testifypods/m;
-
- $out .= "\n\ntestifypods : \n";
-
- foreach my $pod (keys %{$self->{MAN1PODS}},
- keys %{$self->{MAN3PODS}})
- {
- (my $test = $pod) =~ s/\.(pm|pod)$//;
- $test =~ s|/|-|g;
- $test =~ s/^lib\W//;
- $test =~ s/\W/-/;
- $test = "embedded-$test.t";
- $out .= "\t$self->{NOECHO}\$(POD2TEST_EXE) ".
- "$pod t/$test\n";
- }
-
- return $out;
- }
- }
-
Modified: Business-Hours/trunk/lib/Business/Hours.pm
==============================================================================
--- Business-Hours/trunk/lib/Business/Hours.pm (original)
+++ Business-Hours/trunk/lib/Business/Hours.pm Fri Jul 8 10:47:12 2005
@@ -6,25 +6,11 @@
use Time::Local qw/timelocal_nocheck/;
-BEGIN {
- use Exporter ();
- use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
- $VERSION = 0.06;
- @ISA = qw (Exporter);
- #Give a hoot don't pollute, do not export more than needed by default
- @EXPORT = qw ();
- @EXPORT_OK = qw ();
- %EXPORT_TAGS = ();
-}
-
-
-########################################### main pod documentation begin ##
-# Below is the stub of documentation for your module. You better edit it!
-
+our $VERSION = 0.06;
=head1 NAME
-Business::Hours -
+Business::Hours - Calculate business hours in a time period
=head1 SYNOPSIS
@@ -76,9 +62,6 @@
=cut
-############################################# main pod documentation end ##
-
-
# Default business hours are weekdays from 9 am to 6pm
our $BUSINESS_HOURS = ({
0 => { Name => 'Sunday',
@@ -106,24 +89,12 @@
-################################################ subroutine header begin ##
-
-=head2 sample_function
+=head2 new
- Usage : How to use this function/method
- Purpose : What it does
- Returns : What it returns
- Argument : What it wants to know
- Throws : Exceptions and other anomolies
- Comments : This is a sample subroutine header.
- : It is polite to include more pod and fewer comments.
-
-See Also :
+Creates a new L<Business::Hours> object. Takes no arguments.
=cut
-################################################## subroutine header end ##
-
sub new {
my $class = shift;
@@ -184,25 +155,6 @@
Returns a Set::IntSpan of business hours for this period of time.
-
-=begin testing
-
-use_ok (Business::Hours);
-my $hours = Business::Hours->new();
-is(ref($hours), 'Business::Hours');
-# how many business hours were there in the first week.
-my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7)));
-is(ref($hours_span), 'Set::IntSpan');
-
-# Are there 45 working hours
-
-is(cardinality $hours_span, (45 * 60 * 60));
-
-
-
-
-=end testing
-
=cut
@@ -370,50 +322,10 @@
=head2 first_after START
-Returns START if START is within business hours
-Otherwise, returns the next business second after START
-START should be specified in Seconds since the Epoch
-
-=begin testing
-
-use_ok (Business::Hours);
-my $hours = Business::Hours->new();
-my $time;
-
-my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
-my $starttime;
-
-# pick a date that's during business hours
-$starttime = 0;
-($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
-while ($wday == 0 || $wday == 6) {
- $starttime += ( 24 * 60 * 60);
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
-}
-while ( $hour < 9 || $hour >= 18 ) {
- $starttime += ( 4 * 60);
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
-}
-
-$time = $hours->first_after( $starttime );
-is($time, ( $starttime ));
-
-# pick a date that's not during business hours
-$starttime = 0;
-($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
-while ( $xwday != 0 ) {
- $starttime += ( 24 * 60 * 60);
- ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
-}
-
-$time = $hours->first_after( $starttime );
-($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
-is($wday, $xwday+1);
-is($hour, 9);
-is($min, 0);
-is($sec, 0);
-
-=end testing
+Returns START if START is within business hours.
+Otherwise, returns the next business second after START.
+START should be specified in Seconds since the Epoch.
+If it can't find any business hours within thirty days, returns -1.
=cut
@@ -429,8 +341,8 @@
my $end = $start + $period;
my $hours = new Set::IntSpan;
- while (!$hours->first) {
- if ($hours->last >= $start + $MAXTIME) {
+ while ($hours->empty) {
+ if ($end >= $start + $MAXTIME) {
return -1;
}
$hours = $self->for_timespan(Start => $start, End => $end);
@@ -439,38 +351,14 @@
}
return $hours->first;
-
}
=head2 add_seconds START, SECONDS
-Returns a time SECONDS business seconds after START
-START should be specified in Seconds since the Epoch
-
-=begin testing
-
-use_ok (Business::Hours);
-my $hours = Business::Hours->new();
-
-my ($start, $time, $span);
-# pick a date that's during business hours
-$start = (20 * 60 * 60);
-$time = $hours->add_seconds( $start, 30 * 60);
-$span = $hours->for_timespan(Start => $start, End => $time);
-
-# the first second is a business second, too
-is(cardinality $span, (30 * 60)+1);
-
-# pick a date that's not during business hours
-$start = 0;
-$time = $hours->add_seconds( $start, 30 * 60);
-$span = $hours->for_timespan(Start => $start, End => $time);
-
-# the first second is a business second, too
-is(cardinality $span, (30 * 60)+1);
-
-=end testing
+Returns a time SECONDS business seconds after START.
+START should be specified in Seconds since the Epoch.
+If it can't find any business hours within thirty days, returns -1.
=cut
@@ -489,16 +377,13 @@
my $end = $start + $period;
my $hours = new Set::IntSpan;
- while (!$hours->last || $self->between($start, $hours->last) <= $seconds) {
- if ($hours->last >= $start + $MAXTIME) {
+ while ($hours->empty or $self->between($start, $hours->last) <= $seconds) {
+ if ($end >= $start + $MAXTIME) {
return -1;
}
$hours = $self->for_timespan(Start => $start, End => $end);
- # if there's a problem, exit
- return -1 if !$hours->last;
-
- $end = $end + $period;
+ $end += $period;
}
my @elements = elements $hours;
@@ -511,5 +396,3 @@
1; #this line is important and will help the module return a true value
-__END__
-
Added: Business-Hours/trunk/t/1-business-hours.t
==============================================================================
--- (empty file)
+++ Business-Hours/trunk/t/1-business-hours.t Fri Jul 8 10:47:12 2005
@@ -0,0 +1,79 @@
+use strict;
+use warnings;
+use Test::More tests => 11;
+
+BEGIN { use_ok 'Business::Hours' }
+
+{
+ my $hours = Business::Hours->new();
+ is(ref($hours), 'Business::Hours');
+ # how many business hours were there in the first week.
+ my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7) - 1));
+ is(ref($hours_span), 'Set::IntSpan');
+
+ # Are there 45 working hours
+
+ is(cardinality $hours_span, (45 * 60 * 60));
+}
+
+
+{
+ my $hours = Business::Hours->new();
+ my $time;
+
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
+ my $starttime;
+
+ # pick a date that's during business hours
+ $starttime = 0;
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+ while ($wday == 0 || $wday == 6) {
+ $starttime += ( 24 * 60 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+ }
+ while ( $hour < 9 || $hour >= 18 ) {
+ $starttime += ( 4 * 60);
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
+ }
+
+ $time = $hours->first_after( $starttime );
+ is($time, ( $starttime ));
+
+ # pick a date that's not during business hours
+ $starttime = 0;
+ my ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+ while ( $xwday != 0 ) {
+ $starttime += ( 24 * 60 * 60);
+ ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
+ }
+
+ $time = $hours->first_after( $starttime );
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
+ is($wday, $xwday+1);
+ is($hour, 9);
+ is($min, 0);
+ is($sec, 0);
+}
+
+
+{
+ my $hours = Business::Hours->new();
+
+ my ($start, $time, $span);
+ # pick a date that's during business hours
+ $start = (20 * 60 * 60);
+ $time = $hours->add_seconds( $start, 30 * 60);
+ $span = $hours->for_timespan(Start => $start, End => $time);
+
+ # the first second is a business second, too
+ is(cardinality $span, (30 * 60)+1);
+
+ # pick a date that's not during business hours
+ $start = 0;
+ $time = $hours->add_seconds( $start, 30 * 60);
+ $span = $hours->for_timespan(Start => $start, End => $time);
+
+ # the first second is a business second, too
+ is(cardinality $span, (30 * 60)+1);
+}
+
Added: Business-Hours/trunk/t/99-pod-coverage.t
==============================================================================
--- (empty file)
+++ Business-Hours/trunk/t/99-pod-coverage.t Fri Jul 8 10:47:12 2005
@@ -0,0 +1,8 @@
+use warnings;
+use strict;
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.00";
+plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
+all_pod_coverage_ok();
+
Added: Business-Hours/trunk/t/99-pod.t
==============================================================================
--- (empty file)
+++ Business-Hours/trunk/t/99-pod.t Fri Jul 8 10:47:12 2005
@@ -0,0 +1,8 @@
+use warnings;
+use strict;
+
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+
More information about the Rt-commit
mailing list