/[Time-Available]/t/test.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /t/test.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Sun Oct 5 20:55:21 2003 UTC (20 years, 7 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +8 -0 lines
File MIME type: application/x-troff
implementation of interval

1 #!/usr/bin/perl
2
3 use Test::Simple tests => 14;
4
5 use Time::Available qw(:days :fmt_interval);
6
7 my $i = Time::Available->new( start=>'07', end=>'17:15', dayMask=>DAY_WEEKDAY);
8 ok( defined($i) , 'new() work');
9
10 ok( defined($i->{start}) && $i->{start} == 7*60*60, 'start time ok' );
11 ok( defined($i->{end}) && $i->{end} == ((17*60)+15)*60, 'end time ok' );
12
13 my $t = 1 * 24; # 1d
14 $t += 11; # 11 hr
15 $t *= 60;
16 $t += 11; # 11 min
17 $t *= 60;
18 $t += 11; # 11 sec
19
20 ok( fmt_interval($t) eq '1d 11:11:11', 'fmt_interval output ok');
21
22 # 20000 = Thu Jan 1 06:33:20 1970
23 # 30000 = Thu Jan 1 09:20:00 1970
24 # 50000 = Thu Jan 1 14:53:20 1970
25 # 60000 = Thu Jan 1 17:40:00 1970
26
27 # test this timespan (07:00-17:15) with above values
28
29 ok($i->uptime(20000)==36900,'ok');
30 ok($i->uptime(30000)==28500,'ok');
31 ok($i->uptime(50000)==8500,'ok');
32 ok($i->uptime(60000)==0,'ok');
33
34 # create and test timespan which spans over midnight
35
36 $i = Time::Available->new( start=>'17:15', end=>'07:00', dayMask=>DAY_THURSDAY);
37 ok( defined($i->{start}) && $i->{start} == ((17*60)+15)*60, 'end time ok' );
38 ok( defined($i->{end}) && $i->{end} == 7*60*60, 'start time ok' );
39
40 ok($i->uptime(20000)==25900,'ok');
41 ok($i->uptime(30000)==24300,'ok');
42 ok($i->uptime(50000)==24300,'ok');
43 ok($i->uptime(60000)==22800,'ok');
44
45 #$t=time();$u=$i->uptime($t);print STDERR " uptime ( $t $u ) ",scalar localtime $t,": ",fmt_interval($u)," ($u)\n";
46
47
48 $i = Time::Available->new( start=>'07:00', end=>'17:00', dayMask=>DAY_WEEKDAY, DEBUG=>1);
49
50 print STDERR "\n",$i->interval(100000,500001),"\n\n";
51 print STDERR "\n",$i->interval(200100000,200500001),"\n\n";
52 print STDERR "\n",$i->interval(1061478325,1061478819),"\n\n";
53 print STDERR "\n",$i->interval(1061550928,1061551126),"\n\n";
54

  ViewVC Help
Powered by ViewVC 1.1.26