3

I wrote the below code and tested it out on different platforms. I got different results on HP-UX IA64,as compared to other platforms.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    time_t t;
    struct tm *gmt, *lat, ldummy;

    tzset();

    printf("Local timezone: TZ=%s\n\n", getenv("TZ"));

    t = 1394881705;

    lat = localtime(&t);
    printf("Local time is : %s", asctime(lat));

    gmt = gmtime(&t);
    printf("GMT is        : %s", asctime(gmt));

    return 0;
}

OUTPUT:-

Linux

$ ./a.out
Local timezone: TZ=CET

Local time is : Sat Mar 15 12:08:25 2014
GMT is        : Sat Mar 15 11:08:25 2014

SunOs

$ ./a.out
Local timezone: TZ=CET

Local time is : Sat Mar 15 12:08:25 2014
GMT is        : Sat Mar 15 11:08:25 2014

AIX

$ ./a.out  
Local timezone: TZ=CET

Local time is : Sat Mar 15 12:08:25 2014
GMT is        : Sat Mar 15 11:08:25 2014

(This is where the problem is) HP-UX IA64

$ ./a.out
Local timezone: TZ=CET

Local time is : Sat Mar 15 11:08:25 2014
GMT is        : Sat Mar 15 11:08:25 2014

I am trying to understand why the output is differing in case of HP-UZ IA64(Version is 11.31). I could not find any relevant documentation for this eccentric behaviour. Would someone help me with understanding this?

Phalgun
  • 1,181
  • 2
  • 15
  • 42
  • Looks like a CRT or TZDB bug on that platform. How was it compiled (what CRT is it using)? – TypeIA Mar 15 '14 at 17:59
  • Looks like the daylight-savings-time flag was simply set differently on that HP-UX machine – keshlam Mar 15 '14 at 18:05
  • @keshlam You're right, I thought it was the GMT time that was differing, sorry. Yes, this could simply be a DST setting issue. – TypeIA Mar 15 '14 at 18:10
  • If it were a difference in DST setting, wouldn't some of the time zones show as `CEST`? – user4815162342 Mar 15 '14 at 18:31
  • I second @user4815162342. Had it been for a difference in DST setting it should have shown in TZ environment variable, but it simply shows 'TZ=CET'. – Phalgun Mar 17 '14 at 04:23
  • I compiled using 'cc compiler' on all platforms. And @dvnrrs, I did not understand when you said, "How was it compiled (what CRT is it using)". I do not know what is 'CRT'; would you please tell me what it is and how do I find it out? – Phalgun Mar 17 '14 at 04:32
  • What does `tm_tzone` of `struct tm` say? – n. m. could be an AI Mar 17 '14 at 06:14
  • What happens if you set TZ to some other timezone (try PST)? – n. m. could be an AI Mar 17 '14 at 06:20
  • Unfotunately, tm_zone is field is a BSD and GNU extension, and is not visible in a strict ISO C environment. When I set TZ=PST, the output is the same on all platforms mentioned earlier:- Local timezone: TZ=PST Local time is : Sat Mar 15 11:08:25 2014 GMT time is : Sat Mar 15 11:08:25 2014 This is bit of a surprise as PST=GMT-7 – Phalgun Mar 17 '14 at 11:10
  • On HP-UX ia64, when I provide set timezone as, TZ=CET, it simply considers it as being the same as UTC. As per HP-UX documentation at [link](http://goo.gl/cdMkUM) emphasis mine, "TZ can be set using the format: [:]STDoffset[DST[offset][,rule]]" – Phalgun Mar 18 '14 at 10:00

1 Answers1

1

On HP-UX ia64, when I provide set timezone as, TZ=CET, it simply considers it as being the same as UTC. As per HP-UX documentation at link emphasis mine, "TZ can be set using the format: [:]STDoffset[DST[offset][,rule]]" The offset here is mandatory and represents "the value that must be added to local time to arrive at Coordinated Universal Time (UTC)."
So, without offset, HP-UX considers the STD the same as UTC.

Phalgun
  • 1,181
  • 2
  • 15
  • 42