Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-Id: <200506241818.j5OII4wg032180@smtp.hispeed.ch> From: "Luca Wullschleger" To: Subject: strptime error when setting a different TimeZone with export TZ=UTC Date: Fri, 24 Jun 2005 20:18:03 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Virus-Status: Clean X-DCC-spamcheck-02.tornado.cablecom.ch-Metrics: smtp-02.tornado.cablecom.ch 32701; Body=1 Fuz1=1 Fuz2=1 X-IsSubscribed: yes Hi everybody. I have a very specific problem and I'm looking for someone giving me a solution. When I set the TZ environment varialbe TZ to "UTC" and try to execute "date" I get the right date in UTC format: **************** begin $ date Fri Jun 24 20:13:05 WEDT 2005 $ export TZ=UTC $ date Fri Jun 24 18:03:00 UTC 2005 **************** end But if I try to execute the peace of code written in C here below, I have a very strange behaviour. **************** begin $ ./test_time Timezone: WEST-1WEDT-2,M3.5.0/2,M10.5.0/3 TS = 1097712000 LOCAL : Thu Oct 14 02:00:00 2004 UTC : Thu Oct 14 00:00:00 2004 Trying with '13/Oct/2004:17:00:00 -0700' -> 1097712000 ts = 1097704800 LOCAL : Thu Oct 14 00:00:00 2004 UTC : Wed Oct 13 22:00:00 2004 $ export TZ=UTC $ ./test_time Timezone: UTC TS = 1097712000 LOCAL : Thu Oct 14 00:00:00 2004 UTC : Thu Oct 14 00:00:00 2004 Trying with '13/Oct/2004:17:00:00 -0700' -> 1097712000 ts = 25199 LOCAL : Thu Jan 1 06:59:59 1970 <-- problem UTC : Thu Jan 1 06:59:59 1970 <-- problem **************** end As you can see the problem is in in the last 2 lines.. I would like to be able to parse the date in UTC, but it seams that either the strptime or the mktime function do not like the modification of the TZ environment variable. I also tried to printout the broken-down date structure try and it seams to be correct, so I suppose that the problem is with the mktime() function. I know this mktime() function uses some timezone settings from somewhere. I executed this peace of code on a Linux machine and the behaviour is right. It seams that the problem only occurs within Cygwin. I tried everything, google searched it, but I found nothing interesting. Any idea? Thanks a lot for the help... Luca Email: luca DOT wullschleger AT epfl DOT ch **************** file test_time.c #include #include #include #include /** Main method. */ int main(int argc, char **argv) { tzset(); printf("Timezone: %s\n\n",getenv("TZ")); time_t ts = 1097712000; /* "13/Oct/2004:17:30:00" */ printf("TS = %i\n",(int)ts); printf("LOCAL : %s", asctime(localtime(&ts))); printf("UTC : %s", asctime(gmtime(&ts))); printf("\nTrying with '13/Oct/2004:17:00:00 -0700' -> 1097712000\n"); struct tm try; time_t ts2; char date[30] = "13/Oct/2004:17:30:00"; char timezone[4] = "-07"; if ((char *)strptime(date,"%d/%b/%Y:%T",&try) == NULL) { printf("Error with strptime\n"); return 1; } ts2 = mktime(&try) - atoi(timezone)*3600; printf("ts = %i\n",(int)ts2); printf("LOCAL : %s", asctime(localtime(&ts2))); printf("UTC : %s", asctime(gmtime(&ts2))); return (0); } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/