App-olson
    
    
  
  
  
view release on metacpan or search on metacpan
See below for the format in which the absolute time must be stated.
It is expressed as a single character: a "C<+>" indicates DST, and a
"C<->" indicates not DST.
=item B<local_time @> I<absolute-time>
=item B<t @> I<absolute-time>
The local time in a timezone at the specified absolute time.  See below
for the format in which the absolute time must be stated.  A local time
is expressed in the Gregorian calendar in ISO 8601 format: year, month,
day, hour, minute, and second.  The year is four digits, and the other
components two digits.  On output, date is separated from time of day by
a "B<T>", dash and colon separators are used between components, and all
components are emitted.  On input, the separators are optional, "B<T>" is
accepted case insensitively and can be surrounded or replaced with spaces,
and trailing components with the lowest possible value are optional.
=back
Where an absolute time must be used to parameterise an attribute, it
lib/App/olson.pm view on Meta::CPAN
# exceptions
#
sub _is_exception($) {
	return is_string($_[0]) && $_[0] =~ /\A[!?~]\z/;
}
sub _cmp_exception($$) { $_[0] cmp $_[1] }
#
# calendar dates
#
sub _caltime_offset($$) {
	my($rdns, $offset) = @_;
	return $rdns if _is_exception($rdns);
	return $offset if _is_exception($offset);
	my($rdn, $sod) = @$rdns;
	$sod += $offset;
	use integer;
	my $doff = $sod < 0 ? -((86399-$sod) / 86400) : $sod / 86400;
lib/App/olson.pm view on Meta::CPAN
	}
	$h = "00" unless defined $h;
	$mi = "00" unless defined $mi;
	$s = "00" unless defined $s;
	die "hour number $h is out of the range [0, 24)\n" unless $h < 24;
	die "minute number $mi is out of the range [0, 60)\n" unless $mi < 60;
	die "second number $s is out of the range [0, 60)\n" unless $s < 60;
	return [ $rdn, 3600*$h + 60*$mi + $s ];
}
$type{calendar_time} = {
	desc => "calendar time",
	present => \&_present_caltime,
	present_exception_width => 19,
	rx => $caltime_rx,
	parse => \&_parse_caltime,
	cmp => sub { $_[0]->[0] <=> $_[1]->[0] || $_[0]->[1] <=> $_[1]->[1] },
};
my $unix_epoch_rdn = 719163;
my $now_absolute_time;
lib/App/olson.pm view on Meta::CPAN
	present => sub { _present_caltime($_[0])."Z" },
	present_exception_width => 20,
	rx => qr/(?:(?:$caltime_rx) *[Zz]|now)/o,
	parse => sub {
		if($_[0] eq "now") {
			return _now_absolute_time();
		} else {
			return _parse_caltime($_[0]);
		}
	},
	cmp => $type{calendar_time}->{cmp},
};
$type{country_code} = {
	desc => "country code",
	present => sub { $_[0] },
	present_exception_width => 2,
	rx => qr/[A-Za-z]{2}/,
	parse => sub { uc($_[0]) },
	cmp => sub { $_[0] cmp $_[1] },
};
lib/App/olson.pm view on Meta::CPAN
				local $SIG{__DIE__};
				$zone->is_dst_for_datetime($whendt) ? 1 : 0;
			}, $@);
		};
	},
};
$attrclass{t} = $attrclass{local_time} = {
	desc => "local time",
	params => { "\@" => "absolute_time" },
	type => "calendar_time",
	cost => 11,
	get_needs => { z=>undef },
	curry_get => sub {
		my($when) = $_[0]->{"\@"};
		my $get_offs = $attrclass{offset}->{curry_get}->($_[0]);
		return sub { _caltime_offset($when, $get_offs->($_[0])) };
	},
};
sub _parse_attribute_from_gmatch($) {
	type => $App::olson::type{truth},
	check_value => "CODE",
	cost => 10,
	get_needs => { z=>undef },
	xget => "CODE",
};
is_deeply san(pa("dst_status\@now")), san($a);
$a = pa("t\@now");
is_deeply san($a), {
	type => $App::olson::type{calendar_time},
	check_value => "CODE",
	cost => 11,
	get_needs => { z=>undef },
	xget => "CODE",
};
is_deeply san(pa("local_time\@now")), san($a);
1;
( run in 0.417 second using v1.01-cache-2.11-cpan-5dc5da66d9d )