File: localtimetz.t

package info (click to toggle)
libtime-y2038-perl 20100403-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 164 kB
  • sloc: ansic: 811; perl: 497; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (5)
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
35
36
37
38
#!/usr/bin/perl

# Ensure localtime() honors the current time zone

use strict;
use warnings;

use Time::y2038;

use Test::More 'no_plan';

my $Time = time();

SKIP: {
    local $ENV{TZ};

    # Two time zones, different and likely to exist
    my $tz1 = "America/Los_Angeles";
    my $tz2 = "America/Chicago";

    # If the core localtime doesn't respond to TZ, we don't have to.
    skip "localtime does not respect TZ env", 1
      unless do {
          # check that localtime respects changes to $ENV{TZ}
          $ENV{TZ}  = $tz1;
          my $hour  = (CORE::localtime($Time))[2];
          $ENV{TZ}  = $tz2;
          my $hour2 = (CORE::localtime($Time))[2];
          $hour != $hour2;
      };

    # check that localtime respects changes to $ENV{TZ}
    $ENV{TZ}  = $tz1;
    my $hour  = (localtime($Time))[2];
    $ENV{TZ}  = $tz2;
    my $hour2 = (localtime($Time))[2];
    isnt $hour, $hour2, "localtime() honors TZ";
}