Mojar-Cron
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Mojar/Cron/Date.pm view on Meta::CPAN
use overload
'""' => sub { ${$_[0]} },
'<=>' => sub { (${$_[0]} cmp $_[1]) * ($_[2] ? -1 : 1) },
fallback => 1;
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
my $payload = @_ ? shift : ref $proto ? $$proto : $class->today;
bless \$payload => $class;
}
sub today {
my ($d, $m , $y) = (localtime)[3, 4, 5];
return shift->new(sprintf '%04u-%02u-%02u', $y + 1900, $m + 1, $d);
}
sub current {
my ($d, $m , $y) = (gmtime)[3, 4, 5];
return shift->new(sprintf '%04u-%02u-%02u', $y + 1900, $m + 1, $d);
lib/Mojar/Cron/Datetime.pm view on Meta::CPAN
# Zero member
$self = [0,0,0, 0,0,0];
}
elsif (@_ == 1) {
# Pre-generated
croak "Non-ref argument to new ($self)" unless ref($self = shift);
}
else {
$self = [ @_ ];
}
bless $self => $class;
return $self->normalise; # Calculate weekday etc
}
sub from_string {
my ($class, $iso_date) = @_;
$class = ref $class || $class;
if ($iso_date
=~ /^(\d{4})-(\d{2})-(\d{2})(?:T|\s)(\d{2}):(\d{2}):(\d{2})Z?$/) {
return $class->new(life_to_zero($6, $5, $4, $3, $2, $1));
}
lib/Mojar/Cron/Timestamp.pm view on Meta::CPAN
if (ref $class) {
# Clone
$ts = $$class;
$class = ref $class;
carp "Useless arguments to new (@{[ join ',', @_ ]})" if @_;
}
elsif (@_ >= 1) {
# Pre-generated
$ts = ref $_[0] ? ${ shift() } : shift;
}
return bless \$ts => $class;
}
sub now { my $class = shift; $class = ref $class || $class; $class->new(time) }
sub from_string {
my ($class, $iso_date, $local) = @_;
my $sec = 0;
if ($iso_date =~ /^(\d{4})-(\d{2})-(\d{2})(?:T|\s)(\d{2}):(\d{2}):(\d{2})Z?$/) {
$sec = ($local || $class->{is_local})
? mktime($6, $5, $4, $3, $2 - 1, $1 - 1900)
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.428 second using v1.00-cache-2.02-grep-82fe00e-cpan-a086c87fca4 )