| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Bot::IRC plugin for some time functions |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use 5.014; |
|
4
|
1
|
|
|
1
|
|
293514
|
use exact; |
|
|
1
|
|
|
|
|
10
|
|
|
5
|
1
|
|
|
1
|
|
4
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
6
|
|
|
|
|
|
|
use Date::Parse 'str2time'; |
|
7
|
1
|
|
|
1
|
|
801
|
use DateTime; |
|
|
1
|
|
|
|
|
2016
|
|
|
|
1
|
|
|
|
|
59
|
|
|
8
|
1
|
|
|
1
|
|
628
|
use DateTime::Format::Human::Duration; |
|
|
1
|
|
|
|
|
348465
|
|
|
|
1
|
|
|
|
|
41
|
|
|
9
|
1
|
|
|
1
|
|
472
|
use DateTime::Duration; |
|
|
1
|
|
|
|
|
1523
|
|
|
|
1
|
|
|
|
|
27
|
|
|
10
|
1
|
|
|
1
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
579
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.04'; # VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ($bot) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
0
|
5286
|
my $duration = DateTime::Format::Human::Duration->new; |
|
16
|
|
|
|
|
|
|
$bot->hook( |
|
17
|
1
|
|
|
|
|
14
|
{ |
|
18
|
|
|
|
|
|
|
to_me => 1, |
|
19
|
|
|
|
|
|
|
text => qr/ |
|
20
|
|
|
|
|
|
|
^(?<command>date|time|zulu|str2time|str2date|when\s+(?:wa|i)s|ago) |
|
21
|
|
|
|
|
|
|
\b\s*(?<input>.+)?[.,;:?!]*$ |
|
22
|
|
|
|
|
|
|
/ix, |
|
23
|
|
|
|
|
|
|
}, |
|
24
|
|
|
|
|
|
|
sub { |
|
25
|
|
|
|
|
|
|
my ( $bot, $in, $m ) = @_; |
|
26
|
|
|
|
|
|
|
my $command = lc( $m->{command} ); |
|
27
|
0
|
|
|
0
|
|
0
|
|
|
28
|
0
|
|
|
|
|
0
|
my $reply = ''; |
|
29
|
|
|
|
|
|
|
if ( $command eq 'date' ) { |
|
30
|
0
|
|
|
|
|
0
|
$reply = scalar( localtime( $m->{input} || time ) ); |
|
31
|
0
|
0
|
|
|
|
0
|
} |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
0
|
|
|
0
|
elsif ( $command eq 'time' ) { |
|
33
|
|
|
|
|
|
|
$reply = time(); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
0
|
|
|
|
|
0
|
elsif ( $command eq 'zulu' ) { |
|
36
|
|
|
|
|
|
|
$reply = scalar( gmtime( $m->{input} || time ) ); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
0
|
|
0
|
|
|
0
|
elsif ( $command eq 'str2time' ) { |
|
39
|
|
|
|
|
|
|
$reply = str2time( $m->{input} ); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
0
|
|
|
|
|
0
|
elsif ( $command eq 'str2date' ) { |
|
42
|
|
|
|
|
|
|
$reply = scalar( localtime( str2time( $m->{input} ) ) ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
0
|
elsif ( $command eq 'ago' ) { |
|
45
|
|
|
|
|
|
|
$reply = scalar( localtime( DateTime->now->subtract_duration( |
|
46
|
|
|
|
|
|
|
DateTime::Duration->new( |
|
47
|
|
|
|
|
|
|
map { |
|
48
|
|
|
|
|
|
|
$_ . 's' => ( ( $m->{input} =~ /\b(\d+)\s+$_/ ) ? $1 : 0 ) |
|
49
|
|
|
|
|
|
|
} qw( year month week day hour minute second ) |
|
50
|
0
|
0
|
|
|
|
0
|
) |
|
|
0
|
|
|
|
|
0
|
|
|
51
|
|
|
|
|
|
|
)->epoch ) ); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
elsif ( $command =~ /when\s+((?:wa|i)s)/i ) { |
|
54
|
|
|
|
|
|
|
my $dir = ( lc($1) eq 'was' ) ? 'was' : 'is'; |
|
55
|
|
|
|
|
|
|
my $start = str2time( $m->{input} ) || $m->{input}; |
|
56
|
0
|
0
|
|
|
|
0
|
my $dur; |
|
57
|
0
|
|
0
|
|
|
0
|
|
|
58
|
0
|
|
|
|
|
0
|
eval { |
|
59
|
|
|
|
|
|
|
$dur = $duration->format_duration_between( |
|
60
|
0
|
|
|
|
|
0
|
map { DateTime->from_epoch( epoch => $_ ) } $start, time |
|
61
|
|
|
|
|
|
|
) |
|
62
|
0
|
|
|
|
|
0
|
}; |
|
|
0
|
|
|
|
|
0
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$reply = scalar( localtime($start) ) . " $dir $dur " . |
|
65
|
|
|
|
|
|
|
( ( $dir eq 'was' ) ? 'ago' : 'from now' ) . '.' if ($dur); |
|
66
|
0
|
0
|
|
|
|
0
|
} |
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$bot->reply_to($reply) if ($reply); |
|
69
|
|
|
|
|
|
|
}, |
|
70
|
0
|
0
|
|
|
|
0
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
17
|
$bot->helps( time => |
|
73
|
|
|
|
|
|
|
'Various time functions. Usage: ' . join( ', ', |
|
74
|
1
|
|
|
|
|
10
|
'date', |
|
75
|
|
|
|
|
|
|
'time', |
|
76
|
|
|
|
|
|
|
'zulu', |
|
77
|
|
|
|
|
|
|
'str2time <string>', |
|
78
|
|
|
|
|
|
|
'str2date <string>', |
|
79
|
|
|
|
|
|
|
'when was <time>|<"ago" string>', |
|
80
|
|
|
|
|
|
|
'ago <time>|<string>', |
|
81
|
|
|
|
|
|
|
) . '.' |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=encoding UTF-8 |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Bot::IRC::X::Time - Bot::IRC plugin for some time functions |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 VERSION |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
version 1.04 |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=for markdown [](https://github.com/gryphonshafer/Bot-IRC-X-Time/actions?query=workflow%3Atest) |
|
101
|
|
|
|
|
|
|
[](https://codecov.io/gh/gryphonshafer/Bot-IRC-X-Time) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Bot::IRC; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Bot::IRC->new( |
|
108
|
|
|
|
|
|
|
connect => { server => 'irc.perl.org' }, |
|
109
|
|
|
|
|
|
|
plugins => ['Time'], |
|
110
|
|
|
|
|
|
|
)->run; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This L<Bot::IRC> plugin provides some time functions. The following are the |
|
115
|
|
|
|
|
|
|
details: |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 date [<time>] |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the current date and time. If an optional timestamp is provided, it'll |
|
120
|
|
|
|
|
|
|
return the formatted data and time for that timestamp. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 time |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns the current timestamp. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 zulu |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Exactly like C<date> except will return Zulu time. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 str2time <string> |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Accepts most reasonable date and time strings and returns timestamps for those |
|
133
|
|
|
|
|
|
|
values. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 str2date <string> |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Accepts most reasonable date and time strings and returns a formatted date and |
|
138
|
|
|
|
|
|
|
time string. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 when was <time>|<string> |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Accepts a timestamp or a date and time string and returns a duration string |
|
143
|
|
|
|
|
|
|
like: "1 year, 2 months, and 4 hours" |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 ago <duration string> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Accepts a duration string like what would be returned from "when was" and |
|
148
|
|
|
|
|
|
|
returns a formatted date and time string. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
You can look for additional information at: |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over 4 |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Bot::IRC> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<GitHub|https://github.com/gryphonshafer/Bot-IRC-X-Time> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<MetaCPAN|https://metacpan.org/pod/Bot::IRC::X::Time> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<GitHub Actions|https://github.com/gryphonshafer/Bot-IRC-X-Time/actions> |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L<Codecov|https://codecov.io/gh/gryphonshafer/Bot-IRC-X-Time> |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L<CPANTS|http://cpants.cpanauthors.org/dist/Bot-IRC-X-Time> |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L<CPAN Testers|http://www.cpantesters.org/distro/T/Bot-IRC-X-Time.html> |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=for Pod::Coverage init |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Gryphon Shafer <gryphon@cpan.org> |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This software is Copyright (c) 2016-2050 by Gryphon Shafer. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This is free software, licensed under: |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |