Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (35 sloc) 1.11 kB
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
1 package DDG::Goodie::DaysBetween;
1f173be @crazedpsyc Fix abstract in DaysBetween
crazedpsyc authored
2 # ABSTRACT: Give the number of days between two given dates.
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
3
4 use DDG::Goodie;
5 use Date::Calc qw( Date_to_Days);
6 use Time::localtime;
7
ee77f7f @JetFault Change trigger to include days between
JetFault authored
8 triggers startend => "days", "daysbetween", "days_between";
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
9 zci is_cached => 1;
10 zci answer_type => "days_between";
11
12
ff59b4d @crazedpsyc fix daysbetween trigger-stripping regex
crazedpsyc authored
13 handle query_lc => sub {
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
14
ff59b4d @crazedpsyc fix daysbetween trigger-stripping regex
crazedpsyc authored
15 s/^days(?:\s|_)*between//;
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
16 @dates = $_ =~ m#([01]?[0-9])/([0-3]?[0-9])/([0-9]{4}(?=\s|$))#g;
17
18 if(scalar(@dates) == 3) {
19 $tm=localtime;
20 push(@dates, $tm->mon + 1, $tm->mday, $tm->year + 1900);
21 }
22
23 if(scalar(@dates) == 6) {
24
25 eval {
26 $days1 = Date_to_Days(@dates[2], @dates[0], @dates[1]);
27 $days2 = Date_to_Days(@dates[5], @dates[3], @dates[4]);
28 };
29 if ($@) {
30 return;
31 }
32 $daysBetween = abs($days2 - $days1);
0110da4 @nospampleasemam DaysBetween now returns a full sentence
nospampleasemam authored
33 if(/inclusive/) {
34 $daysBetween += 1;
35 $inclusive = ', inclusive';
36 }
37 $startDate = @dates[0] . '/' . @dates[1] . '/' . @dates[2];
38 $endDate = @dates[3] . '/' . @dates[4] . '/' . @dates[5];
39 return 'There are ' . $daysBetween ." days between ". $startDate . ' and ' . $endDate . $inclusive . '.';
d607ce2 @JetFault Goodie to tell the days between two dates, or current date and anothe…
JetFault authored
40 }
41 return;
42 };
43
44 1;
Something went wrong with that request. Please try again.