line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::dategrep::Date; |
2
|
8
|
|
|
8
|
|
27
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
168
|
|
3
|
8
|
|
|
8
|
|
22
|
use warnings; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
143
|
|
4
|
8
|
|
|
8
|
|
20
|
use parent 'Exporter'; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
36
|
|
5
|
8
|
|
|
8
|
|
3935
|
use Date::Manip::Delta; |
|
8
|
|
|
|
|
425357
|
|
|
8
|
|
|
|
|
233
|
|
6
|
8
|
|
|
8
|
|
6570
|
use Date::Manip::Date; |
|
8
|
|
|
|
|
154687
|
|
|
8
|
|
|
|
|
1921
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(intervall_to_epoch date_to_epoch minutes_ago); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub intervall_to_epoch { |
11
|
43
|
|
|
43
|
0
|
61
|
my ( $time, $format ) = @_; |
12
|
43
|
100
|
|
|
|
206
|
if ( $time =~ /^(.*) from (.*)$/ ) { |
13
|
1
|
|
|
|
|
15
|
my ( $delta, $date ) = |
14
|
|
|
|
|
|
|
( Date::Manip::Delta->new($1), Date::Manip::Date->new($2) ); |
15
|
|
|
|
|
|
|
## TODO: $date->is_date is missing in Date::Manip::Date |
16
|
|
|
|
|
|
|
## will be fixed in next major release |
17
|
1
|
50
|
|
|
|
217239
|
if ( $delta->is_delta() ) { ## and $date->is_date() ) { |
18
|
1
|
|
|
|
|
9
|
return $date->calc($delta)->secs_since_1970_GMT(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
42
|
|
|
|
|
189
|
return date_to_epoch( $time, $format ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub minutes_ago { |
25
|
1
|
|
|
1
|
0
|
32
|
my $minutes = shift; |
26
|
1
|
|
|
|
|
16
|
my $now = Date::Manip::Date->new("now"); |
27
|
1
|
|
|
|
|
51407
|
$now->set( 's', 0 ); |
28
|
1
|
|
|
|
|
51
|
my $ago = Date::Manip::Date->new("$minutes minutes ago"); |
29
|
1
|
|
|
|
|
28783
|
$ago->set( 's', 0 ); |
30
|
1
|
|
|
|
|
39
|
return ( $ago->secs_since_1970_GMT(), $now->secs_since_1970_GMT() ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $date; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub date_to_epoch { |
37
|
254
|
|
|
254
|
0
|
273
|
my ( $str, $format ) = @_; |
38
|
254
|
100
|
|
|
|
574
|
if ( !$date ) { |
39
|
8
|
|
|
|
|
100
|
$date = Date::Manip::Date->new(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
254
|
|
|
|
|
45588
|
my $error; |
43
|
254
|
50
|
|
|
|
384
|
if ($format) { |
44
|
254
|
|
|
|
|
1004
|
$error = $date->parse_format( $format, $str ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
254
|
100
|
66
|
|
|
155436
|
if ( !$format or $error ) { |
48
|
38
|
|
|
|
|
134
|
$error = $date->parse($str); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
254
|
100
|
|
|
|
287786
|
return ( undef, $date->err ) if $error; |
52
|
231
|
|
|
|
|
583
|
return ( $date->secs_since_1970_GMT() ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |