DateTime-Moonpig
view release on metacpan or search on metacpan
lib/DateTime/Moonpig.pm view on Meta::CPAN
use namespace::autoclean;
sub new {
my ($base, @arg) = @_;
my $class = ref($base) || $base;
if (@arg == 1) { return $class->from_epoch( epoch => $arg[0] ) }
my %arg = @arg;
$arg{time_zone} = 'UTC' unless exists $arg{time_zone};
bless $class->SUPER::new(%arg) => $class;
}
sub new_datetime {
my ($class, $dt) = @_;
bless $dt->clone => $class;
}
# $a is expected to be epoch seconds
sub plus {
my ($self, $a) = @_;
my $class = ref($self);
my $a_sec = $class->_to_sec($a);
return $class->from_epoch( epoch => $self->epoch + $a_sec,
time_zone => $self->time_zone,
);
lib/DateTime/Moonpig.pm view on Meta::CPAN
$x8 = $birthday - hours(12); # 1969-04-01 14:38:00
C<$birthday> is I<never> modified by any of this. The resulting objects will be in the same time zone as the original object, in this case UTC.
You can add any object to a C<DateTime::Moonpig> object if the other object supports an
C<as_seconds> method. C<DateTime> and C<DateTime::Moonpig> objects do I<not> provide this method.
package MyDaysInterval; # Silly example
sub new {
my ($class, $days) = @_;
bless { days => $days } => $class;
}
sub as_seconds { $_[0]{days} * 86400 }
package main;
my $three_days = MyDaysInterval->new(3);
$y0 = $birthday + $three_days; # 1969-04-05 02:38:00
lib/DateTime/Moonpig.pm view on Meta::CPAN
number of seconds difference between them:
$x0 = $birthday + 10; # 1969-04-02 02:38:10
$z4 = $x0 - $birthday; # 10
$z5 = $birthday - $x0; # -10
package Feb13; # Silly example
sub new {
my ($class) = @_;
bless [ "DUMMY" ] => $class;
}
sub epoch { return 1234567890 } # Feb 13 23:31:30 2009 UTC
package main;
my $feb13 = Feb13->new();
$feb13_dt = DateTime->new( year => 2009,
month => 2,
day => 13,
t/lib/MyDaysInterval.pm view on Meta::CPAN
package MyDaysInterval; # Silly example
sub new {
my ($class, $days) = @_;
bless { days => $days } => $class;
}
sub as_seconds { $_[0]{days} * 86400 }
1;
is($x0->st, "1969-04-02 02:38:10", "x0");
$z4 = $x0 - $birthday; # 10
is($z4, 10, "z4");
$z5 = $birthday - $x0; # -10
is($z5, -10, "z5");
package Feb13; # Silly example
sub new {
my ($class) = @_;
bless [ "DUMMY" ] => $class;
}
sub epoch { return 1234567890 } # Feb 13 23:31:30 2009 UTC
package main;
my $feb13 = Feb13->new();
$feb13_dt = DateTime->new( year => 2009,
month => 2,
day => 13,
( run in 0.296 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )