Permalink
Browse files

Ensure localtime() honors the TZ environment variable.

Also, according to POSIX, ctime64() and mktime64 (which is covered
because it calls mktime).
  • Loading branch information...
1 parent c72c702 commit fbc79371d71ac89259c470ebddbdbfb92b8229cd @schwern schwern committed Apr 2, 2010
Showing with 43 additions and 0 deletions.
  1. +1 −0 perl/Time-y2038/Changes
  2. +1 −0 perl/Time-y2038/MANIFEST
  3. +1 −0 perl/Time-y2038/lib/Time/y2038.xs
  4. +38 −0 perl/Time-y2038/t/localtimetz.t
  5. +2 −0 time64.c
@@ -2,6 +2,7 @@ Next
Bugs
* strict compilers, like Sun's cc, would error because we passed
too many elements to the tm struct. [rt.cpan.org #55225]
+ * Ensure localtime() honors the TZ environment variable.
20100225 Thu Feb 25 23:09:15 PST 2010
@@ -11,6 +11,7 @@ MANIFEST.SKIP
META.yml
munge_config
t/everywhere.t
+t/localtimetz.t
t/time.t
t/timegm.t
typemap
@@ -138,6 +138,7 @@ localtime(...)
}
}
+ tzset();
err = localtime64_r(&when, &date);
if( err == NULL )
@@ -0,0 +1,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";
+}
View
@@ -805,6 +805,7 @@ char *ctime64_r( const Time64_T* time, char* result ) {
/* Non-thread safe versions of the above */
struct TM *localtime64(const Time64_T *time) {
+ tzset();
return localtime64_r(time, &Static_Return_Date);
}
@@ -817,5 +818,6 @@ char *asctime64( const struct TM* date ) {
}
char *ctime64( const Time64_T* time ) {
+ tzset();
return asctime64(localtime64(time));
}

0 comments on commit fbc7937

Please sign in to comment.