Newsgroup: it.comp.lang.c
Titolo: Problema nel calcolare il fuso orario in Brasile

Ho un problema sul calcolo del timezone.
Qualcuno leggendo in seguito ha qualche idea ???
Grazie,
Mimmo.
Sul seguente sito
http://www.timezoneconverter.com/cgi-bin/tzc.tzc
ottengo per la data 2003/01/01 00:00:00:
      00:00:00 Wed Jan 01 2003 in Europe/Rome converts to
      21:00:00 Tue Dec 31 2002 in Brazil/East
      DST* is not in effect on this date/time in Europe/Rome
      DST* is in effect on this date/time in Brazil/East
      *Daylight Saving Time
Sotto Unix:
tmpbuf:2003/01/01 00:00:00     <-------------L'orario
t_time.tm_isdst:0              <------------flag di ora legale
Time in seconds:        1041375600  <------------julian date
Local time:   Tue Dec 31 21:00:00 2002  <-----------Ora locale a
Brazil/East
t_time.tm_isdst:1             <-----------flag di ora legale
tmpbuf:2002/12/31 21:00:00
**************************************
Il risultato ottenuto sembra corretto!!!!!!!
**************************************
Invece sempre sul sito per la data 2003/08/08 13:48:23 ottengo:
      13:48:23 Fri Aug 08 2003 in Europe/Rome converts to
      08:48:23 Fri Aug 08 2003 in Brazil/East
      DST* is in effect on this date/time in Europe/Rome
      DST* is not in effect on this date/time in Brazil/East
      *Daylight Saving Time
mentre sotto Unix mi "avanza" un'ora:
tmpbuf:2003/08/13 13:48:19
t_time.tm_isdst:1
Time in seconds:        1060778899
Local time:             Wed Aug 13 09:48:19 2003
localt.tm_isdst:0
tmpbuf:2003/08/13 09:48:19
**************************************
Il risultato ottenuto e' sbagliato
**************************************
Questo e' il codice di test:
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>
int timezoneconverter(char *local_tz, char *tz, char *string_date,
char *format_date, char **result_date)
{
    char buf[256];
    struct tm t_time;
    struct tm *pt_time, *localt;
    time_t julian_date = -1;
    int ret = -1;
 
    tzset();
    memset(&buf, 0, sizeof(buf) );
    memset(&t_time, 0, sizeof(struct tm) );
    t_time.tm_isdst = -1;
    string_date = strptime(string_date, format_date, &t_time);
    if (NULL == string_date) {
        printf("string_date null\n");
        return (-1);
    }
    julian_date = mktime(&t_time);
    if(-1 == julian_date) {
        return (-1);
    }
printf("t_time.tm_isdst:%d\n", t_time.tm_isdst);
    strcpy(buf, "TZ=");
    strcat(buf, tz);
    putenv(buf);
    printf( "Time in seconds:\t%ld\n", julian_date );
    localt = (struct tm *) localtime(&julian_date);
    if (NULL == (struct tm *) localt) {
        return (-1);
    }
    printf( "Local time:\t\t%s", asctime(localt));
printf("localt.tm_isdst:%d\n", localt->tm_isdst);
    memset(&buf, 0, sizeof(buf) );
    ret = strftime(buf, sizeof(buf), format_date, localt);
    if (0 == ret) {
        printf("strftime error\n");
        return (-1);
    }
 
    *result_date = strdup(buf);
    /* Imposto il vecchio valore */
    memset(&buf, 0, sizeof(buf) );
    strcpy(buf, "TZ=");
    strcat(buf, local_tz);
    putenv(buf);
    return (0);
}
int main()
{
    char tmpbuf[128], ampm[] = "AM";
    char *tmp = NULL;
    printf("----->Europe/Rome to Brazil/East<-----\n");
    strcpy(tmpbuf,  "2003/01/01 00:00:00");
    printf("tmpbuf:%s\n", tmpbuf);
    timezoneconverter("Europe/Rome", "Brazil/East", tmpbuf, "%Y/%m/%d
%H:%M:%S", &tmp);
    strcpy(tmpbuf, tmp);
    printf("tmpbuf:%s\n", tmpbuf);
    printf("----->Europe/Rome to Brazil/East<-----\n");
    strcpy(tmpbuf,  "2003/08/13 13:48:19");
    printf("tmpbuf:%s\n", tmpbuf);
    timezoneconverter("Europe/Rome", "Brazil/East", tmpbuf, "%Y/%m/%d
%H:%M:%S", &tmp);
    strcpy(tmpbuf, tmp);
    printf("tmpbuf:%s\n", tmpbuf);
return(0);
}

 egrep -A13 '.+Function.+putenv'
 - Function: int putenv (char *STRING)
     The `putenv' function adds or removes definitions from the
     environment.  If the STRING is of the form `NAME=VALUE', the
     definition is added to the environment.  Otherwise, the STRING is
     interpreted as the name of an environment variable, and any
     definition for this variable in the environment is removed.
 
     The difference to the `setenv' function is that the exact string
     given as the parameter STRING is put into the environment.  If the
     user should change the string after the `putenv' call this will
     reflect in automatically in the environment.  This also requires
     that STRING is no automatic variable which scope is left before the
     variable is removed from the environment.  The same applies of
     course to dynamically allocated variables which are freed later.
[fok@localhost fok]$
---live action---
Ho corretto questo e altri svarioni qui e la' e mi funziona come dovrebbe.
Non posto qui la mia versione perche' mi pare non sia il NG giusto.
-- 
error: can't find .signature file 'a_punto_foco_presso_virgilio_punto_it'

...


 comp.lang.c)
Sei OT in comp.lang.c, ovviamente.
