mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 13:59:47 +01:00
b5c10b73d9
`ban` command will not save ban to unban-timeouts if "forever" is used.
39 lines
713 B
Perl
39 lines
713 B
Perl
#!/usr/bin/env perl
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
package PBot::Utils::ParseDate;
|
|
|
|
require Exporter;
|
|
our @ISA = qw/Exporter/;
|
|
our @EXPORT = qw/parsedate/;
|
|
|
|
use Time::HiRes qw/gettimeofday/;
|
|
|
|
require Time::ParseDate;
|
|
|
|
sub parsedate {
|
|
my $input = shift @_;
|
|
my $now = gettimeofday;
|
|
my @inputs = split /(?:,?\s+and\s+|\s*,\s*)/, $input;
|
|
|
|
my $seconds = 0;
|
|
foreach my $input (@inputs) {
|
|
return -1 if $input =~ m/forever/i;
|
|
$input .= ' seconds' if $input =~ m/^\d+$/;
|
|
|
|
my $parse = Time::ParseDate::parsedate($input, NOW => $now);
|
|
|
|
if (not defined $parse) {
|
|
return (0, "I don't know what '$input' means.\n");
|
|
} else {
|
|
$seconds += $parse - $now;
|
|
}
|
|
}
|
|
|
|
return $seconds;
|
|
}
|
|
|
|
1;
|