DateTime-TimeZone
view release on metacpan or search on metacpan
lib/DateTime/TimeZone/OlsonDB/Observance.pm view on Meta::CPAN
&& $dt <= $self->utc_start_datetime;
## no critic (Variables::ProhibitReusedNames)
my $until = $self->until( $zone->last_change->offset_from_std );
next if $until && $dt >= $until;
my $change = DateTime::TimeZone::OlsonDB::Change->new(
type => 'rule',
utc_start_datetime => $dt,
local_start_datetime => $dt + DateTime::Duration->new(
seconds => $self->total_offset + $rule->offset_from_std
),
short_name =>
$self->formatted_short_name( $rule->letter, $rule ),
observance => $self,
rule => $rule,
);
if ($DateTime::TimeZone::OlsonDB::DEBUG) {
## no critic (InputOutput::RequireCheckedSyscalls)
print "Adding rule change ...\n";
$change->_debug_output;
}
$zone->add_change($change);
}
}
}
sub _sorted_rules_for_year {
my $self = shift;
my $year = shift;
## no critic (BuiltinFunctions::ProhibitComplexMappings)
my @rules = (
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map {
my $dt = $_->utc_start_datetime_for_year(
$year,
$self->offset_from_utc, 0
);
[ $_, $dt ]
}
grep {
$_->min_year <= $year
&& ( ( !$_->max_year ) || $_->max_year >= $year )
} $self->rules
);
my %rules_by_month;
for my $rule (@rules) {
push @{ $rules_by_month{ $rule->month() } }, $rule;
}
# In some cases we have both a "max year" rule and a "this year" rule for
# a given month's change. In that case, we want to pick the more specific
# ("this year") rule, not apply both. This only matters for zones that
# have a winter transition that follows the Islamic calendar to deal with
# Ramadan. So far this has happened with Cairo, El_Aaiun, and other zones
# in northern Africa.
my @final_rules;
for my $month ( sort { $a <=> $b } keys %rules_by_month ) {
push @final_rules, @{ $rules_by_month{$month} };
}
return @final_rules;
}
## no critic (Subroutines::ProhibitBuiltinHomonyms)
sub until {
my $self = shift;
my $offset_from_std = shift || $self->offset_from_std;
return unless defined $self->until_year;
my $utc = DateTime::TimeZone::OlsonDB::utc_datetime_for_time_spec(
spec => $self->until_time_spec,
year => $self->until_year,
month => $self->until_month,
day => $self->until_day,
offset_from_utc => $self->offset_from_utc,
offset_from_std => $offset_from_std,
);
return $utc;
}
## use critic
sub until_year { $_[0]->{until}[0] }
sub until_month {
return 1 unless defined $_[0]->{until}[1];
return $DateTime::TimeZone::OlsonDB::MONTHS{ $_[0]->{until}[1] };
}
sub until_day {
return 1 unless defined $_[0]->{until}[2];
my ( undef, $day ) = DateTime::TimeZone::OlsonDB::parse_day_spec(
$_[0]->{until}[2],
$_[0]->until_month,
$_[0]->until_year,
);
return $day;
}
sub until_time_spec {
defined $_[0]->{until}[3] ? $_[0]->{until}[3] : '00:00:00';
}
## no critic (Subroutines::ProhibitExcessComplexity)
sub _first_rule {
my $self = shift;
my $last_offset_from_utc = shift;
my $last_offset_from_std = shift;
return unless $self->rules;
my $date = $self->utc_start_datetime
( run in 2.176 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )