This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge git://github.com/codejoust/zeroclickinfo-goodies into unix-time
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package DDG::Goodie::UnixTime; | ||
|
||
use DDG::Goodie; | ||
|
||
zci answer_type => "time_conversion"; | ||
zci is_cached => 1; | ||
triggers startend => "unixtime", "time", "timestamp", "datetime", "epoch"; | ||
|
||
handle remainder => sub { | ||
|
||
my $time_input = int(length ($_) >= 13 ? ($_ / 1000) : ($_ + 0)); | ||
|
||
if ($time_input >= 0){ | ||
|
||
my $my_time = localtime($time_input); | ||
|
||
return "Unix Time Conversion: " . $my_time if $my_time; | ||
|
||
} | ||
|
||
return; | ||
|
||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use DDG::Test::Goodie; | ||
|
||
zci answer_type => 'time_conversion'; | ||
zci is_cached => 1; | ||
|
||
ddg_goodie_test( | ||
[qw( | ||
DDG::Goodie::UnixTime | ||
)], | ||
'time 0' => test_zci('Unix Time Conversion: Wed Dec 31 19:00:00 1969'), | ||
'time 1335233773453' => test_zci('Unix Time Conversion: Mon Apr 23 22:16:13 2012'), | ||
'time 1335233773' => test_zci('Unix Time Conversion: Mon Apr 23 22:16:13 2012'), | ||
'time 5325423' => test_zci('Unix Time Conversion: Tue Mar 3 10:17:03 1970'), | ||
'time 53492399294' => test_zci('Unix Time Conversion: Sat Feb 7 18:48:14 3665') | ||
); | ||
|
||
done_testing; |