App-dategrep
view release on metacpan or search on metacpan
lib/App/dategrep/Date.pm view on Meta::CPAN
}
sub minutes_ago {
my ( $self, $minutes ) = @_;
my $to = $self->{now};
$to -= $to % 60;
my $from = $to - $minutes * 60;
return ( $from, $to );
}
sub guess_format {
my ( $self, $line ) = @_;
for my $format ( @{ $self->{formats} } ) {
my $date = eval { App::dategrep::Strptime::strptime( $line, $format ) };
warn "$@" if $@;
return $format if $date;
}
return;
}
sub to_epoch {
my ( $self, $line, $format, $defaults ) = @_;
$format ||= $self->guess_format($line);
if ( !$format ) {
return ( undef, "No date found in line $line" );
}
my $t =
eval { App::dategrep::Strptime::strptime( $line, $format, $defaults ) };
if ( !$t ) {
return ( undef, $@ );
lib/App/dategrep/Iterator.pm view on Meta::CPAN
return;
}
sub format_has_year {
App::dategrep::Strptime::has_year( shift->{format} );
}
sub to_epoch {
my ( $self, $line ) = @_;
if ( !$self->{format} ) {
my $format = $self->{date}->guess_format($line);
if ($format) {
$self->{format} = $format;
}
else {
return;
}
}
my $seconds =
$self->{date}->to_epoch( $line, $self->{format} );
( run in 0.924 second using v1.01-cache-2.11-cpan-702932259ff )