line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::dategrep::Date; |
2
|
9
|
|
|
9
|
|
35
|
use strict; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
208
|
|
3
|
9
|
|
|
9
|
|
33
|
use warnings; |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
186
|
|
4
|
9
|
|
|
9
|
|
30
|
use parent 'Exporter'; |
|
9
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
48
|
|
5
|
9
|
|
|
9
|
|
5114
|
use Date::Manip::Delta; |
|
9
|
|
|
|
|
496699
|
|
|
9
|
|
|
|
|
245
|
|
6
|
9
|
|
|
9
|
|
7657
|
use Date::Manip::Date; |
|
9
|
|
|
|
|
176040
|
|
|
9
|
|
|
|
|
2221
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(intervall_to_epoch date_to_epoch minutes_ago); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub intervall_to_epoch { |
11
|
47
|
|
|
47
|
0
|
74
|
my ( $time, $format ) = @_; |
12
|
47
|
100
|
|
|
|
164
|
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
|
|
|
|
224837
|
if ( $delta->is_delta() ) { ## and $date->is_date() ) { |
18
|
1
|
|
|
|
|
9
|
return $date->calc($delta)->secs_since_1970_GMT(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
46
|
|
|
|
|
102
|
return date_to_epoch( $time, $format ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub minutes_ago { |
25
|
1
|
|
|
1
|
0
|
2
|
my $minutes = shift; |
26
|
1
|
|
|
|
|
15
|
my $now = Date::Manip::Date->new("now"); |
27
|
1
|
|
|
|
|
46148
|
$now->set( 's', 0 ); |
28
|
1
|
|
|
|
|
55
|
my $ago = Date::Manip::Date->new("$minutes minutes ago"); |
29
|
1
|
|
|
|
|
28059
|
$ago->set( 's', 0 ); |
30
|
1
|
|
|
|
|
49
|
return ( $ago->secs_since_1970_GMT(), $now->secs_since_1970_GMT() ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $date; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub date_to_epoch { |
37
|
226
|
|
|
226
|
0
|
266
|
my ( $str, $format ) = @_; |
38
|
226
|
100
|
|
|
|
425
|
if ( !$date ) { |
39
|
9
|
|
|
|
|
157
|
$date = Date::Manip::Date->new(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
226
|
|
|
|
|
54974
|
my $error; |
43
|
226
|
50
|
|
|
|
426
|
if ($format) { |
44
|
226
|
|
|
|
|
637
|
$error = $date->parse_format( $format, $str ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
226
|
100
|
66
|
|
|
143907
|
if ( !$format or $error ) { |
48
|
41
|
|
|
|
|
139
|
$error = $date->parse($str); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
226
|
100
|
|
|
|
340745
|
return ( undef, $date->err ) if $error; |
52
|
202
|
|
|
|
|
510
|
return ( $date->secs_since_1970_GMT() ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |