/usr/lib/perl5/Date/Pcalendar.pm is in libdate-pcalc-perl 6.1-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | ###############################################################################
## ##
## Copyright (c) 2000 - 2009 by Steffen Beyer. ##
## All rights reserved. ##
## ##
## This package is free software; you can redistribute it ##
## and/or modify it under the same terms as Perl itself. ##
## ##
###############################################################################
package Date::Pcalendar;
BEGIN { eval { require bytes; }; }
use strict;
use vars qw( @ISA @EXPORT @EXPORT_OK $VERSION );
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw();
$VERSION = '6.1';
use Carp::Clan qw(^Date::);
use Date::Pcalc::Object qw(:ALL);
use Date::Pcalendar::Year qw( check_year empty_period );
sub new
{
my($class) = shift;
my($profile) = shift;
my($language) = shift || 0;
my($self);
$self = [ ];
$class = ref($class) || $class || 'Date::Pcalendar';
bless($self, $class);
$self->[0] = { };
$self->[1] = $profile;
$self->[2] = $language;
$self->[3] = [@_];
return $self;
}
sub year
{
my($self) = shift;
my($year) = shift_year(\@_);
&check_year($year);
if (defined $self->[0]{$year})
{
return $self->[0]{$year};
}
else
{
return $self->[0]{$year} =
Date::Pcalendar::Year->new( $year, $self->[1], $self->[2], @{$self->[3]} );
}
}
sub cache_keys
{
my($self) = shift;
return( sort {$a<=>$b} keys(%{$self->[0]}) );
}
sub cache_vals
{
my($self) = shift;
local($_);
return( map $self->[0]{$_}, sort {$a<=>$b} keys(%{$self->[0]}) );
}
sub cache_clr
{
my($self) = shift;
$self->[0] = { };
}
sub cache_add
{
my($self) = shift;
my($year);
while (@_)
{
$year = shift_year(\@_);
$self->year($year);
}
}
sub cache_del
{
my($self) = shift;
my($year);
while (@_)
{
$year = shift_year(\@_);
if (exists $self->[0]{$year})
{
delete $self->[0]{$year};
}
}
}
sub date2index
{
my($self) = shift;
my(@date) = shift_date(\@_);
return $self->year($date[0])->date2index(@date);
}
sub labels
{
my($self) = shift;
my($year);
my(@date);
my(%result);
if (@_)
{
@date = shift_date(\@_);
return $self->year($date[0])->labels(@date);
}
else
{
local($_);
%result = ();
foreach $year (keys(%{$self->[0]}))
{
grep( $result{$_} = 0, $self->year($year)->labels() );
}
return wantarray ? (keys %result) : scalar(keys %result);
}
}
sub search
{
my($self,$pattern) = @_;
my($year);
my(@result);
@result = ();
foreach $year (sort {$a<=>$b} keys(%{$self->[0]}))
{
push( @result, $self->year($year)->search($pattern) );
}
return wantarray ? (@result) : scalar(@result);
}
sub tags
{
my($self) = shift;
my(%result) = ();
my(@date);
if (@_)
{
@date = shift_date(\@_);
return $self->year($date[0])->tags(@date);
}
else { return \%result; }
}
sub delta_workdays
{
my($self) = shift;
my($yy1,$mm1,$dd1) = shift_date(\@_);
my($yy2,$mm2,$dd2) = shift_date(\@_);
my($including1,$including2) = (shift,shift);
my($days,$empty,$year);
$days = 0;
$empty = 1;
if ($yy1 == $yy2)
{
return $self->year($yy1)->delta_workdays(
$yy1,$mm1,$dd1, $yy2,$mm2,$dd2, $including1,$including2);
}
elsif ($yy1 < $yy2)
{
unless (($mm1 == 12) && ($dd1 == 31) && (!$including1))
{
$days += $self->year($yy1)->delta_workdays(
$yy1,$mm1,$dd1, $yy1,12,31, $including1,1);
$empty = 0;
}
unless (($mm2 == 1) && ($dd2 == 1) && (!$including2))
{
$days += $self->year($yy2)->delta_workdays(
$yy2, 1, 1, $yy2,$mm2,$dd2, 1,$including2);
$empty = 0;
}
for ( $year = $yy1 + 1; $year < $yy2; $year++ )
{
$days += $self->year($year)->delta_workdays(
$year,1,1, $year,12,31, 1,1);
$empty = 0;
}
}
else
{
unless (($mm2 == 12) && ($dd2 == 31) && (!$including2))
{
$days -= $self->year($yy2)->delta_workdays(
$yy2,$mm2,$dd2, $yy2,12,31, $including2,1);
$empty = 0;
}
unless (($mm1 == 1) && ($dd1 == 1) && (!$including1))
{
$days -= $self->year($yy1)->delta_workdays(
$yy1, 1, 1, $yy1,$mm1,$dd1, 1,$including1);
$empty = 0;
}
for ( $year = $yy2 + 1; $year < $yy1; $year++ )
{
$days -= $self->year($year)->delta_workdays(
$year,1,1, $year,12,31, 1,1);
$empty = 0;
}
}
&empty_period() if ($empty);
return $days;
}
sub add_delta_workdays
{
my($self) = shift;
my($yy,$mm,$dd) = shift_date(\@_);
my($days) = shift;
my($date,$rest,$sign);
if ($days == 0)
{
$rest = $self->year($yy)->date2index($yy,$mm,$dd); # check date
$date = Date::Pcalc->new($yy,$mm,$dd);
return wantarray ? ($date,$days) : $date;
}
else
{
$sign = ($days > 0) ? +1 : -1;
($date,$rest,$sign) = $self->year($yy)->add_delta_workdays($yy,$mm,$dd,$days,$sign);
while ($sign)
{
($date,$rest,$sign) = $self->year($date)->add_delta_workdays($date,$rest,$sign);
}
return wantarray ? ($date,$rest) : $date;
}
}
sub is_full
{
my($self) = shift;
my(@date) = shift_date(\@_);
my($year) = $self->year($date[0]);
return $year->vec_full->bit_test( $year->date2index(@date) );
}
sub is_half
{
my($self) = shift;
my(@date) = shift_date(\@_);
my($year) = $self->year($date[0]);
return $year->vec_half->bit_test( $year->date2index(@date) );
}
sub is_work
{
my($self) = shift;
my(@date) = shift_date(\@_);
my($year) = $self->year($date[0]);
return $year->vec_work->bit_test( $year->date2index(@date) );
}
1;
__END__
|