line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::dategrep::Date; |
2
|
8
|
|
|
8
|
|
31
|
use strict; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
190
|
|
3
|
8
|
|
|
8
|
|
26
|
use warnings; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
172
|
|
4
|
8
|
|
|
8
|
|
27
|
use parent 'Exporter'; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
43
|
|
5
|
8
|
|
|
8
|
|
4120
|
use Date::Manip::Delta; |
|
8
|
|
|
|
|
413367
|
|
|
8
|
|
|
|
|
220
|
|
6
|
8
|
|
|
8
|
|
6623
|
use Date::Manip::Date; |
|
8
|
|
|
|
|
153801
|
|
|
8
|
|
|
|
|
2006
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(intervall_to_epoch date_to_epoch minutes_ago); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub intervall_to_epoch { |
11
|
43
|
|
|
43
|
0
|
62
|
my ( $time, $format ) = @_; |
12
|
43
|
100
|
|
|
|
138
|
if ( $time =~ /^(.*) from (.*)$/ ) { |
13
|
1
|
|
|
|
|
16
|
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
|
|
|
|
250006
|
if ( $delta->is_delta() ) { ## and $date->is_date() ) { |
18
|
1
|
|
|
|
|
68
|
return $date->calc($delta)->secs_since_1970_GMT(); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
42
|
|
|
|
|
119
|
return date_to_epoch( $time, $format ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub minutes_ago { |
25
|
1
|
|
|
1
|
0
|
2
|
my $minutes = shift; |
26
|
1
|
|
|
|
|
17
|
my $now = Date::Manip::Date->new("now"); |
27
|
1
|
|
|
|
|
51364
|
$now->set( 's', 0 ); |
28
|
1
|
|
|
|
|
83
|
my $ago = Date::Manip::Date->new("$minutes minutes ago"); |
29
|
1
|
|
|
|
|
29031
|
$ago->set( 's', 0 ); |
30
|
1
|
|
|
|
|
51
|
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
|
262
|
my ( $str, $format ) = @_; |
38
|
254
|
100
|
|
|
|
483
|
if ( !$date ) { |
39
|
8
|
|
|
|
|
201
|
$date = Date::Manip::Date->new(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
254
|
|
|
|
|
50784
|
my $error; |
43
|
254
|
50
|
|
|
|
410
|
if ($format) { |
44
|
254
|
|
|
|
|
640
|
$error = $date->parse_format( $format, $str ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
254
|
100
|
66
|
|
|
146339
|
if ( !$format or $error ) { |
48
|
38
|
|
|
|
|
123
|
$error = $date->parse($str); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
254
|
100
|
|
|
|
263323
|
return ( undef, $date->err ) if $error; |
52
|
231
|
|
|
|
|
522
|
return ( $date->secs_since_1970_GMT() ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |