Debian Codegraph @

t/metdate.t

raw
1 #!/usr/bin/perl -I. -w
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Time::ParseDate;
7 use Time::CTime;
8 #-use POSIX qw(tzset);
9 use Time::Piece;
10
11 my $finished;
12 END { ok($finished, 'finished') if defined $finished }
13
14 $ENV{'LANG'} = 'C';
15 $ENV{'TZ'} = 'PST8PDT';
16
17 my @x = localtime(785307957);
18 my @y = gmtime(785307957);
19 my $hd = $y[2] - $x[2];
20 $hd += 24 if $hd < 0;
21 $hd %= 24;
22 if ($hd != 8) {
23 plan skip_all => "It seems localtime() does not honor \$ENV{TZ} when set in the test script.";
24 exit 0;
25 }
26
27 $ENV{'TZ'} = 'MET';
28
29 @x = localtime(785307957);
30 @y = gmtime(785307957);
31 $hd = $y[2] - $x[2];
32 $hd += 24 if $hd < 0;
33 $hd %= 24;
34 if ($hd != 23) {
35 plan skip_all => "It seems localtime() does not honor \$ENV{TZ} when set in the test script.";
36 exit 0;
37 }
38
39 plan 'no_plan';
40 $finished = 0;
41
42 $ENV{TZ} = 'MET';
43
44 my $t0 = parsedate("2009-10-25 02:55:00");
45 my $t1 = parsedate("+ 1 hour", NOW => scalar(parsedate("2009-10-25 02:55:00")));
46 my $lt1 = scalar(localtime($t1));
47
48 is($t0, 1256435700, "testing TZ=MET seconds");
49 is($t1, 1256439300, "testing TZ=MET seconds +1 h");
50 is($lt1, "Sun Oct 25 03:55:00 2009", "testing TZ=MET +1 h localtime");
51
52 $ENV{TZ} = "PST8PDT";
53
54 my $p0 = parsedate("2009-11-01 01:55:00");
55 my $p1 = parsedate("+ 1 hour", NOW => scalar(parsedate("2009-11-01 01:55:00")));
56 my $lp0 = scalar(localtime($p0));
57 my $lp1 = scalar(localtime($p1));
58 my $lpz0 = strftime("%R %Z",localtime($p0));
59 my $lpz1 = strftime("%R %Z",localtime($p1));
60
61 is($p0, 1257065700, "testing PST8PDT");
62 is($lp0, "Sun Nov 1 01:55:00 2009", "testing PST8PDT localtime");
63 is($p1, 1257069300, "testing PST8PDT");
64 is($lp1, "Sun Nov 1 01:55:00 2009", "testing PST8PDT localtime");
65 is($lpz0, "01:55 PDT", "zone 0");
66 is($lpz1, "01:55 PST", "zone 1");
67
68 $finished = 1;
69