File: epoch.t

package info (click to toggle)
libtime-format-perl 1.12-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 288 kB
  • ctags: 40
  • sloc: perl: 534; makefile: 4
file content (34 lines) | stat: -rwxr-xr-x 675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/perl -I..

# Test epoch-time formatting.
# Based on a bug report by Adam Schneider, 11 June 2009

use strict;
use Test::More;

BEGIN { $Time::Format::NOXS = 1 }
use Time::Format;

my @test_inputs =
    (
     100000000,
      99999999,
      10000000,
       9999999,
       1000000,
        999999,
    );

plan tests => scalar @test_inputs;

my $tnum = 0;
foreach my $epoch (@test_inputs)
{
    my @t = localtime $epoch;
    $t[4]++;
    $t[5] += 1900;
    my $expected = sprintf '%04d/%02d/%02d %02d:%02d:%02d', @t[5,4,3, 2,1,0];

    eval {is time_format('yyyy/mm/dd hh:mm:ss', $epoch), $expected, "Test case $tnum"} ;
    ++$tnum;
}