Date-Manip
view release on metacpan or search on metacpan
internal/tzdata view on Meta::CPAN
} elsif ($opts =~ /lastlist/) {
$val = " $val ],";
} elsif ($opts =~ /list/) {
$val = " $val,";
} else {
$val = "=> $val,";
}
} else {
$val .= ',';
}
$wid = length($val) if (! $wid);
my $rep = $wid-length($val);
$rep = 0 if ($rep < 0);
print $out ' 'x$indent,$val,' 'x$rep;
}
print $out "\n";
}
############################################################################
# DEALING WITH THE ORDER OF ELEMENTS
# This takes a hash:
# $in = { ELE => SUBELE => [YEAR1,YEAR2] }
# and returns a hash of the form:
# $out = { ELE => [ SUBELE, YEAR1, YEAR2,
# SUBELE, YEAR1, YEAR2, ... ] }
#
# The order of the elements sorted based on the range.
#
sub _order_elements {
my($in) = @_;
my $out;
foreach my $ele (keys %$in) {
my @in = _sort_by_years($$in{$ele});
$$out{$ele} = [];
foreach my $subele (@in) {
my($year1,$year2) = @{ $$in{$ele}{$subele} };
push(@{ $$out{$ele} },($subele,$year1,$year2));
}
}
return $out;
}
# This sorts the keys of a hash of the form:
# $hash = { ELE => [YEAR1,YEAR2] }
# by years.
#
# o An element that is active now always comes before one that isn't
# active now.
# i.e. [2000-2020] < [1900-2000] (now = 2010)
#
# o A modern European timezone (WET, CET, EET) comes before others.
#
# o An Antarctica element comes after one that is not Antarctica
#
# o A military timezone (A-Z) comes after one that is not
#
# o A UT/UTC/*GMT* timezone comes after one that is not
#
# o An element that is active later comes before one that is active
# earlier.
# i.e. [X-1970] < [X-1960]; [X-2040] < [X-2020]
#
# o An element that is active further in the past comes before one
# that is active later.
# i.e. [1930-X] < [1940-X]
#
# o Alphabetize the rest.
#
sub _sort_by_years {
my($hash) = @_;
return sort { __sort_by_years($$hash{$a},$$hash{$b},$a,$b) } keys %$hash;
}
sub __sort_by_years {
my($a,$b,$namea,$nameb) = @_;
# Find out which elements are currently active
my $curra = ($$a[0] <= $curry && $$a[1] >= $curry ? 1 : 0);
my $currb = ($$b[0] <= $curry && $$b[1] >= $curry ? 1 : 0);
# An element that is active now always comes before one that isn't
# active now.
if ($curra != $currb) {
return -1 if ($curra);
return 1;
}
# A modern European timezone (WET, CET, EET) comes before others.
if ($namea =~ /^(WET|CET|EET)$/) {
return -1;
} elsif ($nameb =~ /^(WET|CET|EET)$/) {
return 1;
}
# An Antarctica element comes after one that is not Antarctica
if ($namea =~ /Antarctica/) {
if ($nameb =~ /Antarctica/) {
return $namea cmp $nameb;
} else {
return 1;
}
} elsif ($nameb =~ /Antarctica/) {
return -1;
}
# A military timezone (A-Z) comes after one that is not
if ($namea =~ /^[A-Z]$/) {
if ($nameb =~ /^[A-Z]$/) {
return $namea cmp $nameb;
} else {
return 1;
}
} elsif ($nameb =~ /^[A-Z]$/) {
return -1;
}
# A UT/UTC/*GMT* timezone comes after one that is not
if ($namea =~ /UT/ || $namea =~ /GMT/) {
if ($nameb =~ /UT/ || $nameb =~ /GMT/) {
return $namea cmp $nameb;
} else {
return 1;
}
} elsif ($nameb =~ /UT/ || $nameb =~ /GMT/) {
return -1;
}
# An element that is active later comes before one that is active
# earlier.
if ($$a[1] != $$b[1]) {
return -1 if ($$a[1] > $$b[1]);
return 1;
}
# An element that is active further in the past comes before one
# that is active later.
if ($$a[0] != $$b[0]) {
return -1 if ($$a[0] < $$b[0]);
return 1;
}
# We'll order anything else as America < Europe < Asia < other
my ($posa,$posb);
if ($namea =~ /^America/) { $posa = 1; }
elsif ($namea =~ /^Europe/) { $posa = 2; }
elsif ($namea =~ /^Asia/) { $posa = 3; }
else { $posa = 4; }
if ($nameb =~ /^America/) { $posb = 1; }
elsif ($nameb =~ /^Europe/) { $posb = 2; }
( run in 3.533 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )