Make getTimeZone cross-platform consistent by always considering the TZ environment variable.

The current behaviour of getTimeZone is system dependent.  On Linux, using glibc we get the following result:

$ ghc -package time-1.4 -e 'System.Posix.Env.putEnv "TZ=EST5EDT" >> Data.Time.getCurrentTimeZone >>= print >> System.Posix.Env.putEnv "TZ=PST8PDT" >> Data.Time.getCurrentTimeZone >>= print'
EDT
EDT

Under MacOS X we get a different result

$ ghc -package time-1.4 -e 'System.Posix.Env.putEnv "TZ=EST5EDT" >> Data.Time.getCurrentTimeZone >>= print >> System.Posix.Env.putEnv "TZ=PST8PDT" >> Data.Time.getCurrentTimeZone >>= print'
EDT
PDT

The underlying problem is that POSIX does not fully specify the behaviour of localtime_r, upon which getTimeZone relies.  POSIX.1-2008 says: 

    Unlike localtime(), the localtime_r() function is not required to set tzname. 

"not required" means that localtime_r may or may not set tzname.  MacOS X's behaviour sets tzname on every call to localtime_r.

On the other hand, Linux, using glibc, the behaviour of localtime_r is outstandingly complicated.  Upon the first call to localtime_r (or more techincially upon the first call to tzset_internal) it will set tzname based upon the value in the TZ environment variable, but upon subsequent calls, localtime_r will *not* set the tzname.

This leads to the bizzare behaviour under Linux whereby the value used by getTimeZone (and getCurrentTimeZone) will always use the value of the TZ environment variable during the first call, and it is impossible to change it again.  The only workaround available to a Haskell programer is to call tzset, which is can only be found in another package.

This patch calls tzset() before each call to localtime_r() which forces tzname to be set from the TZ enviroment call.  The result is that on all platforms one gets the sane result of

$ ghc -package time-1.4.1 -e 'System.Posix.Env.putEnv "TZ=EST5EDT" >> Data.Time.getCurrentTimeZone >>= print >> System.Posix.Env.putEnv "TZ=PST8PDT" >> Data.Time.getCurrentTimeZone >>= print'
EDT
PDT
Regression test for getTimeZone.

The localtime_r call made from getTimeZone may or may not perform a tzset().
In particular, in glibc, a tzset() will only be performed the first time a process runs localtime_r.

This added regression test will fail on implementations like glibc that only
perform a tzset() on the first call to localtime_r.

A fix to make getTimeZone always call tzset() can be found in patch:

[Make getTimeZone cross-platform consistent by always considering the TZ environment variable.
oconnorr@google.com**20130610222254
detabify cbits
Derive Typeable instances
use throwErrnoIfMinus1 gettimeofday for consistency in error handling
Merge tag '1_4_1' of http://code.haskell.org/time/ into ghc-head