diff --git a/lib/DDG/Goodie/Hijri.pm b/lib/DDG/Goodie/Hijri.pm
index ed05e24df..61b71dc1c 100644
--- a/lib/DDG/Goodie/Hijri.pm
+++ b/lib/DDG/Goodie/Hijri.pm
@@ -7,17 +7,38 @@ zci answer_type => "date";
triggers any => 'hijri', 'gregorian';
+my $gregorian_calendar_wiki =
+ 'Gregorian calendar';
+my $hijri_calendar_wiki =
+ 'Hijri calendar';
+
handle query_lc => sub {
- return unless my ($gd, $gm, $gy, $gh) = $_ =~ /^(\d{0,2})(?:\/|\,)(\d{0,2})(?:\/|\,)(\d{3,4})\s+(?:on\s+the|in)\s+(?:gregorian|hijri)\s+(?:calendar|date|time)\s+is\s+(?:on\s+the|in)\s+(gregorian|hijri)\s+(?:calendar|date|time)$/;
- last if($gd>31);
- last if($gm>12);
- my $hd;
- my $hm;
- my $hy;
- ($hd, $hm, $hy) = g2h($gd, $gm, $gy) if ($gh eq 'hijri');
- ($hd, $hm, $hy) = h2g($gd, $gm, $gy) if ($gh eq 'gregorian');
- return $hd . '/' . $hm . '/' . $hy;
+ return unless my ($gd, $gm, $gy, $requested_calendar) = $_ =~
+ /^
+ (\d{0,2})(?:\/|,)(\d{0,2})(?:\/|,)(\d{3,4})\s+
+ (?:
+ (?:on\s+the)\s+
+ (?:gregorian|hijri)\s+
+ (?:calendar|date|time)\s+
+ is\s+
+ )?
+ (?:
+ (?:(?:in|on|to)(?:\s+the|in)?)\s+
+ )?
+ (gregorian|hijri)\s*
+ (?:calendar|date|time|years|months|days)?
+ $/x;
+ return unless ($gd<31 and $gm<12);
+ my ($hd, $hm, $hy) = $requested_calendar eq 'hijri' ?
+ g2h($gd, $gm, $gy) : h2g($gd, $gm, $gy);
+ my $input_date = "$gd/$gm/$gy";
+ my $converted_date = "$hd/$hm/$hy";
+ return "$input_date on the "
+ . ($requested_calendar eq 'hijri' ?
+ "$gregorian_calendar_wiki is $converted_date on the $hijri_calendar_wiki" :
+ "$hijri_calendar_wiki is $converted_date on the $gregorian_calendar_wiki");
};
+
1;