delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/04/14/05:09:29

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_00,SARE_SUB_PCT_LETTER,TW_YG,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4DA6B9BA.2020500@lysator.liu.se>
Date: Thu, 14 Apr 2011 11:09:14 +0200
From: Peter Rosin <peda AT lysator DOT liu DOT se>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: strftime trouble with %z
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi!

I'm getting somewhat troublesome output from the below STC.
It seems as if gmtime mucks with something, or that
localtime is not filling in everything it needs to?

------------------8<---(zone.c)---------
#include <stdio.h>
#include <time.h>

int main(void)
{
	char zone[6];
	struct tm *tm;
	time_t now = time(NULL);

	tm = localtime(&now);
	strftime(zone, sizeof(zone), "%z", tm);
	printf("%s %d %d\n", zone, timezone, tm->tm_isdst);

	tm = localtime(&now);
	strftime(zone, sizeof(zone), "%z", tm);
	printf("%s %d %d\n", zone, timezone, tm->tm_isdst);

	tm = gmtime(&now);

	tm = localtime(&now);
	strftime(zone, sizeof(zone), "%z", tm);
	printf("%s %d %d\n", zone, timezone, tm->tm_isdst);

	return 0;
}
------------------8<--------------------

I expect three equal lines, e.g.
+0200 -3600 1
+0200 -3600 1
+0200 -3600 1

but I get this on Cygwin:
+0200 -3600 1
+0200 -3600 1
+0000 -3600 1

$ cygcheck -c gcc4 cygwin
Cygwin Package Information
Package              Version        Status
cygwin               1.7.9-1        OK
gcc4                 4.3.4-4        OK

FWIW, I have tested the STC on Linux and Solaris 10 and they
behave as I expected...

Cheers,
Peter

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019