Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge git://github.com/codejoust/zeroclickinfo-goodies into unix-time
Browse files Browse the repository at this point in the history
  • Loading branch information
majuscule committed May 14, 2012
2 parents ca9ee6a + fc57801 commit 701446e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/DDG/Goodie/UnixTime.pm
@@ -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;
22 changes: 22 additions & 0 deletions t/UnixTime.t
@@ -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;

0 comments on commit 701446e

Please sign in to comment.