line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TimeTracker::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Utility Methods/Functions for App::TimeTracker |
4
|
|
|
|
|
|
|
our $VERSION = '3.008'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
98
|
use strict; |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
410
|
|
7
|
13
|
|
|
13
|
|
128
|
use warnings; |
|
13
|
|
|
|
|
40
|
|
|
13
|
|
|
|
|
325
|
|
8
|
13
|
|
|
13
|
|
289
|
use 5.010; |
|
13
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
90
|
use Scalar::Util qw(blessed); |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
915
|
|
11
|
13
|
|
|
13
|
|
8099
|
use Term::ANSIColor; |
|
13
|
|
|
|
|
108453
|
|
|
13
|
|
|
|
|
987
|
|
12
|
13
|
|
|
13
|
|
114
|
use Exporter; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
519
|
|
13
|
13
|
|
|
13
|
|
84
|
use parent qw(Exporter); |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
114
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(pretty_date now error_message warning_message); |
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub error_message { |
20
|
1
|
|
|
1
|
0
|
4
|
_message( 'bold red', @_ ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub warning_message { |
24
|
0
|
|
|
0
|
0
|
0
|
_message( 'bold yellow', @_ ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _message { |
28
|
1
|
|
|
1
|
|
4
|
my ( $color, $message, @params ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
5
|
my $string = sprintf( $message, @params ); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
8
|
print color $color; |
33
|
1
|
|
|
|
|
120
|
print $string; |
34
|
1
|
|
|
|
|
8
|
say color 'reset'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub pretty_date { |
38
|
3
|
|
|
3
|
0
|
11
|
my ($date) = @_; |
39
|
|
|
|
|
|
|
|
40
|
3
|
50
|
33
|
|
|
32
|
unless ( blessed $date |
41
|
|
|
|
|
|
|
&& $date->isa('DateTime') ) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
0
|
return $date; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
3
|
|
|
|
|
10
|
my $now = now(); |
47
|
3
|
|
|
|
|
10
|
my $yesterday = now()->subtract( days => 1 ); |
48
|
3
|
50
|
|
|
|
3479
|
if ( $date->dmy eq $now->dmy ) { |
|
|
0
|
|
|
|
|
|
49
|
3
|
|
|
|
|
89
|
return $date->hms(':'); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
elsif ( $date->dmy eq $yesterday->dmy ) { |
52
|
0
|
|
|
|
|
0
|
return 'yesterday ' . $date->hms(':'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
0
|
return $date->dmy('.') . ' ' . $date->hms(':'); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub now { |
61
|
20
|
|
|
20
|
0
|
162
|
my $dt = DateTime->now(); |
62
|
20
|
|
|
|
|
7246
|
$dt->set_time_zone('local'); |
63
|
20
|
|
|
|
|
18821
|
return $dt; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding UTF-8 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
App::TimeTracker::Utils - Utility Methods/Functions for App::TimeTracker |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 3.008 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Thomas Klausner <domm@plix.at> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2021 by Thomas Klausner. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
90
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |