bin/53899: mktime gives wrong result in Central timezone
Barry at FreeBSD.org
Barry at FreeBSD.org
Sun Jun 29 10:10:11 PDT 2003
>Number: 53899
>Category: bin
>Synopsis: mktime gives wrong result in Central timezone
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sun Jun 29 10:10:08 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Barry Pederson
>Release: FreeBSD 4.8-RELEASE i386
>Organization:
>Environment:
System: FreeBSD eden.barryp.org 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Sat Apr 5 12:35:50 CST 2003 barryp at eden.barryp.org:/usr/obj/usr/src/sys/BARRYP i386
>Description:
The mktime function seems to give an incorrect result when the timezone
is set to US Central time. I first noticed this when running Zope3 (Python)
unittests, but can also demonstrate the problem using Perl.
>How-To-Repeat:
Execute mktime() with the same parameters, but vary the TZ enviroment
variable. Here is a shell script and a perl script to demonstrate:
------ tzdemo.sh -----------
#!/bin/sh
for tz in 'EST5EDT' 'CST6CDT' 'MST7MDT' 'PST8PDT'
do
export TZ=$tz;
/usr/bin/env perl tzdemo.pl $tz
done
----------------------------
------ tzdemo.pl -----------
#!/usr/bin/env perl
use POSIX;
# An arbitrary unix timestamp and its
# gmtime() equivalent.
#
$test_time = 1055176982;
@test_gm = (2, 43, 16, 9, 5, 103, 1, 159, 0);
# You could also say:
#
# @test_gm = gmtime($test_time);
# Convert test time back to a unix timestamp, but since
# mktime() assumes localtime, the result should vary
# according to the current timezone setting
#
$result = mktime(@test_gm);
# Calculate the difference, in hours, between what mktime()
# came up with for a local value and the initial GMT time
# we started with.
#
$diff = ($result - $test_time) / 3600;
print "$ARGV[0] $result $diff\n";
----------------------------
The expected output is:
EST5EDT 1055194982 5
CST6CDT 1055198582 6
MST7MDT 1055202182 7
PST8PDT 1055205782 8
The actual output I get is:
EST5EDT 1055194982 5
CST6CDT 1055194982 5
MST7MDT 1055202182 7
PST8PDT 1055205782 8
The second line (CST6CDT) should not have the same numbers.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list