Data-OpeningHours
    
    
  
  
  
view release on metacpan or search on metacpan
LICENSE
MANIFEST
META.json
META.yml
README
cpanfile
dist.ini
lib/Data/OpeningHours.pm
lib/Data/OpeningHours/Calendar.pm
lib/Data/OpeningHours/Hours.pm
t/calendar.t
t/hours.t
t/next-open.t
t/release-pod-syntax.t
lib/Data/OpeningHours.pm view on Meta::CPAN
package Data::OpeningHours;
use strict;
use 5.008_005;
our $VERSION = '0.4.2';
use parent 'Exporter';
our @EXPORT_OK = qw/is_open/;
sub is_open {
    my ($calendar, $now) = @_;
    return $calendar->is_open($now);
}
1;
=head1 NAME
Data::OpeningHours - Is a shop is open or closed at this moment?
=head1 SYNOPSYS
t/calendar.t view on Meta::CPAN
use strict;
use Test::More;
use Data::OpeningHours 'is_open';
use Data::OpeningHours::Calendar;
my $calendar = Data::OpeningHours::Calendar->new();
ok($calendar);
isa_ok($calendar, 'Data::OpeningHours::Calendar');
$calendar->set_week_day(1 => []);
$calendar->set_week_day(2 => []);
$calendar->set_week_day(3 => [ ['10:00','12:00'] ]);
$calendar->set_week_day(4 => [ ['10:00','12:00'] ]);
$calendar->set_week_day(5 => []);
$calendar->set_week_day(6 => []);
$calendar->set_week_day(7 => [ [ '10:00', '12:00' ], ['14:00','16:00'] ]);
ok(!$calendar->is_open_on_week_day(1, '10:00'));
ok(!$calendar->is_open_on_week_day(2, '10:00'));
ok($calendar->is_open_on_week_day(3, '10:30'));
ok($calendar->is_open_on_week_day(7, '11:30'));
ok($calendar->is_open_on_week_day(7, '10:00'));
ok($calendar->is_open_on_week_day(7, '15:00'));
ok($calendar->is_open_on_week_day(7, '15:01'));
ok($calendar->is_open_on_week_day(7, '15:59'));
$calendar->set_special_day('2012-01-01' => []);
$calendar->set_special_day('2012-01-02' => []);
$calendar->set_special_day('2012-01-03' => [ ['10:00','12:00'] ]);
ok(!$calendar->is_open_on_special_day('2012-01-01', '10:00'));
ok(!$calendar->is_open_on_special_day('2012-01-02', '10:00'));
ok($calendar->is_open_on_special_day('2012-01-03', '10:00'));
ok($calendar->is_open(DateTime->new(
    year   => 2012,
    month  => 5,
    day    => 17,
    hour   => 10,
    minute => 30,
    second => 0,
)));
ok(!$calendar->is_open(DateTime->new(
    year   => 2012,
    month  => 5,
    day    => 14,
    hour   => 10,
    minute => 30,
    second => 0,
)));
ok(!$calendar->is_open(DateTime->new(
    year   => 2012,
    month  => 1,
    day    => 1,
    hour   => 10,
    minute => 30,
    second => 0,
)));
ok($calendar->is_open(DateTime->new(
    year   => 2012,
    month  => 1,
    day    => 3,
    hour   => 10,
    minute => 30,
    second => 0,
)));
done_testing();
t/next-open.t view on Meta::CPAN
use strict;
use Test::More;
use Data::OpeningHours 'is_open';
use Data::OpeningHours::Calendar;
my $calendar = Data::OpeningHours::Calendar->new();
ok($calendar);
isa_ok($calendar, 'Data::OpeningHours::Calendar');
$calendar->set_week_day(1 => []);
$calendar->set_week_day(2 => []);
$calendar->set_week_day(3 => [ ['10:00','12:00'] ]);
$calendar->set_week_day(4 => [ ['10:00','12:00'] ]);
$calendar->set_week_day(5 => []);
$calendar->set_week_day(6 => []);
$calendar->set_week_day(7 => [ [ '10:00', '12:00' ], ['14:00','16:00'] ]);
$calendar->set_special_day('2012-01-01' => []);
$calendar->set_special_day('2012-01-02' => []);
$calendar->set_special_day('2012-01-03' => [ ['10:00','12:00'] ]);
my $next_open = $calendar->next_open(DateTime->new(
    year   => 2012,
    month  => 1,
    day    => 2,
    hour   => 16,
    minute => 30,
    second => 0,
));
is($next_open->year, 2012);
is($next_open->month, 1);
is($next_open->day, 3);
is($next_open->hour, 10);
is($next_open->minute, 0);
$next_open = $calendar->next_open(DateTime->new(
    year   => 2012,
    month  => 1,
    day    => 3,
    hour   => 16,
    minute => 30,
    second => 0,
));
is($next_open->year, 2012);
is($next_open->month, 1);
is($next_open->day, 4);
is($next_open->hour, 10);
is($next_open->minute, 0);
$next_open = $calendar->next_open(DateTime->new(
    year   => 2012,
    month  => 1,
    day    => 5,
    hour   => 16,
    minute => 30,
    second => 0,
));
is($next_open->year, 2012);
is($next_open->month, 1);
is($next_open->day, 8);
( run in 0.516 second using v1.01-cache-2.11-cpan-c333fce770f )