M
mimmo
I have a problem while calculating timezone (from Europe/Rome to
Brazil/East).
Can someone help me ??
Thank you,
Mimmo.
On this site
http://www.timezoneconverter.com/cgi-bin/tzc.tzc
I have for this date 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
On Unix:
tmpbuf:2003/01/01 00:00:00 <-------------date
t_time.tm_isdst:0 <------------Daylight Saving Time flag
Time in seconds: 1041375600 <------------julian date
Local time: Tue Dec 31 21:00:00 2002 <-----------local time in
Brazil/East
t_time.tm_isdst:1 <-----------Daylight Saving Time flag
tmpbuf:2002/12/31 21:00:00
**************************************
Result seems OK
**************************************
Instead for date 2003/08/08 13:48:23 I have:
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
but on Unix there's a difference of one hour:
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 (!!!!!!!!!!)
**************************************
Result is not right!!!!!!!
**************************************
This is my code for testing it:
#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);
/* Setting old TZ value */
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);
}
Brazil/East).
Can someone help me ??
Thank you,
Mimmo.
On this site
http://www.timezoneconverter.com/cgi-bin/tzc.tzc
I have for this date 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
On Unix:
tmpbuf:2003/01/01 00:00:00 <-------------date
t_time.tm_isdst:0 <------------Daylight Saving Time flag
Time in seconds: 1041375600 <------------julian date
Local time: Tue Dec 31 21:00:00 2002 <-----------local time in
Brazil/East
t_time.tm_isdst:1 <-----------Daylight Saving Time flag
tmpbuf:2002/12/31 21:00:00
**************************************
Result seems OK
**************************************
Instead for date 2003/08/08 13:48:23 I have:
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
but on Unix there's a difference of one hour:
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 (!!!!!!!!!!)
**************************************
Result is not right!!!!!!!
**************************************
This is my code for testing it:
#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);
/* Setting old TZ value */
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);
}